Skip to content

Instantly share code, notes, and snippets.

@stephenLee
Created September 20, 2012 00:47
Show Gist options
  • Save stephenLee/3753293 to your computer and use it in GitHub Desktop.
Save stephenLee/3753293 to your computer and use it in GitHub Desktop.
Scala case class
abstract class Expr
case class Var(name: String) extends Expr
case class Number(num: Double) extends Expr
case class UnOp(operator: String, arg: Expr) extends Expr
case class BinOp(operator: String, left: Expr, right: Expr) extends Expr
val v = Var("x")
val op = BinOp("+", Number(1), v)
v.name
op.left
op.right == Var("x")
op.copy(operator = "-")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment