Skip to content

Instantly share code, notes, and snippets.

@privateblue
Last active August 29, 2015 14:03
Show Gist options
  • Save privateblue/03fdc732a818050e91c3 to your computer and use it in GitHub Desktop.
Save privateblue/03fdc732a818050e91c3 to your computer and use it in GitHub Desktop.
sealed trait Expr
case class Num(n: Int) extends Expr
case class Add(e1: Expr, e2: Expr) extends Expr
case class Sub(e1: Expr, e2: Expr) extends Expr
def value(e: Expr): Int = e match {
case Num(n) => n
case Add(e1, e2) => value(e1) + value(e2)
case Sub(e1, e2) => value(e1) - value(e2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment