All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gapt.grammars.instantiateRS.scala Maven / Gradle / Ivy

The newest version!
package gapt.grammars

import gapt.expr._
import cats.instances.list._
import cats.syntax.traverse._
import gapt.expr.subst.Substitution
import gapt.expr.util.freeVariables

object instantiateRS {

  def apply(recursionScheme: RecursionScheme, terms: Set[Expr]): RecursionScheme = {
    val sts = terms.groupBy { _.ty }.withDefaultValue(Set())

    recursionScheme.copy(rules = recursionScheme.rules flatMap {
      case rule @ Rule(Apps(nt, args), rhs) =>
        args.filterNot { _.isInstanceOf[Var] }.flatMap { freeVariables(_) }.traverse { v => sts(v.ty).map { v -> _ }.toList }.map { Substitution(_)(rule) }
    })
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy