Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created July 11, 2015 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shigemk2/492c3b804ec97f39403a to your computer and use it in GitHub Desktop.
Save shigemk2/492c3b804ec97f39403a to your computer and use it in GitHub Desktop.
sealed trait Expr
case class N(n: Int) extends Expr
case class Var(x: String, a: Int, n: Int) extends Expr
case class Add(n: Expr*) extends Expr
case class Mul(n: Expr*) extends Expr
def add(xs: List[Expr]): Expr = xs match {
case List() => N(0)
case List(xs) => xs
case xs => Add(xs: _*) // Add(List(N(1), N(2), Var(x,2,2)))
}
println(add(List(N(1),N(2),Var("x",2,2))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment