Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class Tree {
- case class Sum(left : Tree, right : Tree) extends Tree;
- case class Var(n : String) extends Tree;
- case class Const(v : Int) extends Tree;
- type Enviroment = String => Int;
- def eval(tree : Tree, env : Enviroment) : Int tree = match {
- case Sum(left, right) => eval(left, env) + eval(right, env)
- case Var(n) => env(n)
- case Const(v) => v
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment