I have a quite simple Scala code where I wanted to apply pattern matching:
trait Expr
case class Number(n: Int) extends Expr
case class Sum(a: Expr, b: Expr) extends Expr
case class Prod(a: Expr, b: Expr) extends Expr
def eval(e: Expr): Int = e match
case Number(n) => n
case Sum(a, b) => eval(a) + eval(b)
case Prod(a, b) => eval(a) * eval(b)
But when I run the code the error rises: "Number cannot be used as an extractor in a pattern because it lacks an unapply or unapplySeq method"
What should I do to avoid this error? Thank you