Inheritance is bad you say? I bet your "Haskell" can't do this!
sealed trait Integer
sealed trait Nat extends Integer
case object Zero extends Nat
case class Succ(pred: Nat) extends Nat
case class Negate(nonzero: Succ) extends Integer
Conversation
Is this inheritance or just subtyping though? I sometimes get confused at the difference.
2
1
Replying to
Granted, Haskellers are weird when it comes to subtyping too though.
Haskell does have subtyping though.
For example:
forall a. Nat a => a <: Int
forall a. Fractional a => a <: forall a. Nat a => a
You can even have multiple inheritance, because type-classes can have multiple parents.
2


