Skip to content

Instantly share code, notes, and snippets.

@7shi
Forked from shigemk2/11-233937.scala
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7shi/9542e56e07cb0d2b182a to your computer and use it in GitHub Desktop.
Save 7shi/9542e56e07cb0d2b182a 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(x) => x
case _ => Add(xs.toArray: _*) // Add(WrappedArray(N(1), N(2), Var(x,2,2)))
}
println(add(List(N(1),N(2),Var("x",2,2))))
println(Add(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