Hacker News new | ask | show | jobs
by slashnull 4045 days ago
Ahhhh, *variance.

The definitive explanation of why inheritance should always be avoided in favour of implementation of abstract interfaces.

1 comments

Interfaces have variance too, as long as they give rise to a subtyping relationship (which, in most languages that have them, they do).
Ha! Cunningham's law.

I see that many OOP languages (of various purity) have interfaces that may be extended by other interfaces. Is that what you're talking about?

I also found that *variance is used in the context of Haskell, but it seems to be far from being widely used.

Haskell being my template of a language with a good-looking interplay of polymorphism and algebraic typing.

variance is used in Haskell all the time. Haskell's subtyping/type-subsumption relation is less pervasive than an OO language's, but it's critical. Furthermore, variance is more fundamental than subtyping. It is not at all a stretch to say that the type mechanics of function composition are based on contravariance/covariance matching.