Created
July 11, 2015 15:47
-
-
Save shigemk2/492c3b804ec97f39403a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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