sealed
trait
Expr[A] extends AnyRef
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
An
Expr
describes a simple structure for algebraic expressions. Generally, a typeExpr[A]
indicates thatA
has some structure that mirrorsExpr
. To get at this symmetry, you must use the type classCoexpr[A]
. This let's us switch between typesA
andExpr[A]
, giving us the ability to extract structure from a typeA
, traverse, and construct the expression tree ofA
, without having to deal withA
as a concrete type.Using
Coexpr
let's us provide further general constructors and pattern matchers. These are defined as the same name as the case class, but without theExpr
appended. So, we can, for example, pattern match on an instancea
of the generic typeA
. Suppose we wanted to map patterns like ab + ac to a(b + c), then we could do the following:a match { case Add(Mul(a, b), Mul(c, d)) if a == c => Mul(a, Add(b, d)) case _ => a }