Guest User

Untitled

a guest
Sep 9th, 2012
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.39 KB | None | 0 0
  1. abstract class Tree {
  2.    
  3.     case class Sum(left : Tree, right : Tree) extends Tree;
  4.     case class Var(n : String) extends Tree;
  5.     case class Const(v : Int) extends Tree;
  6.     type Enviroment = String => Int;
  7.     def eval(tree : Tree, env : Enviroment) : Int tree = match {
  8.     case Sum(left, right) => eval(left, env) + eval(right, env)
  9.     case Var(n) => env(n)
  10.     case Const(v) => v
  11.     }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment