scala - If case class inheritance is prohibited, how to represent this? -
i trying create case classes explained in this article
sealed abstract case 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 however, getting following error in intellij. understand why prohibited (why case-to-case inheritance prohibited in scala). alternate way here?
error:(2, 13) case class literal has case ancestor a$a34.a$a34.exp, case-to-case inheritance prohibited. overcome limitation, use extractors pattern match on non-leaf nodes. case class literal(x:int) extends exp ^
exp shouldn't use case keyword. is, sealed abstract case class rarely, if ever, make sense use.
in specific case, thing sealed abstract case class exp() auto-generated companion object exp has unapply method. , unapply method won't useful, because there isn't extract generic exp. is, care decomposing add, sub, etc.
this 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
Comments
Post a Comment