trait
Subst extends AnyRef
Abstract Value Members
-
abstract
def
apply[A](v: A): A
-
abstract
def
asMap: Map[Sym, Any]
-
abstract
def
compose(that: Subst): Subst
-
abstract
def
lookup(x: Sym): Option[Any]
Concrete Value Members
-
final
def
!=(arg0: AnyRef): Boolean
-
final
def
!=(arg0: Any): Boolean
-
final
def
##(): Int
-
final
def
==(arg0: AnyRef): Boolean
-
final
def
==(arg0: Any): Boolean
-
final
def
asInstanceOf[T0]: T0
-
def
clone(): AnyRef
-
final
def
eq(arg0: AnyRef): Boolean
-
def
equals(arg0: Any): Boolean
-
def
finalize(): Unit
-
final
def
getClass(): Class[_]
-
def
hashCode(): Int
-
final
def
isInstanceOf[T0]: Boolean
-
final
def
ne(arg0: AnyRef): Boolean
-
final
def
notify(): Unit
-
final
def
notifyAll(): Unit
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
-
def
toString(): String
-
final
def
wait(): Unit
-
final
def
wait(arg0: Long, arg1: Int): Unit
-
final
def
wait(arg0: Long): Unit
Inherited from AnyRef
Inherited from Any
A substitution that binds Syms to arbitrary values.
Substitutions are an abstract data type. See the companion object, which has methods Subst.singleton and Subst.empty that you can use to create new substitutions.
A
Subst
is generic in the sense that it recurs into any tuple or case class (or any type that extendsscala.Product
). A value that extends HasSym is treated as a variable to be substituted:You can create a hierarchy of case classes and substitute into them:
The explicit type parameter to the substitution is important. Without an explicit type parameter, Scala will infer that the return type of the following expressions as
EVar
:subst(EVar(x)) // returns EInt(99) with type EVar!
Here is another example, where the variable is in the type and we're substituting into an expression:
It is possible for a term to use a type-variable in a context that is incompatible with a substitution. In the following example, the substitution binds
x
to anExp
, but the term usesx
as aTyp
: