I am trying to create the case classes as explained in this article
sealed abstract case class Exp()
case class Literal(x:Int) extends Exp
case class Add(a:E
Exp
shouldn't use the case
keyword. That is, a sealed abstract case class
will rarely, if ever, make sense to use.
In this specific case, the only extra thing you get from sealed abstract case class Exp()
is an auto-generated companion object Exp
that has an unapply
method. And this unapply
method won't be very useful, because there isn't anything to extract from the generic Exp
. That is, you only care about decomposing Add
, Sub
, etc.
This is just fine:
sealed abstract class Exp
case class Literal(x: Int) extends Exp
case class Add(a: Exp, b: Exp) extends Exp
case class Sub(a: Exp, b: Exp) extends Exp