4 ms·
Ahhhh, *variance. The definitive explanation of why inheritance should always be avoided in favour of implementation of abstract interfaces.
by slashnull 11y ago
Ahhhh, *variance.
The definitive explanation of why inheritance should always be avoided in favour of implementation of abstract interfaces.
- pcwalton 11y agoInterfaces have variance too, as long as they give rise to a subtyping relationship (which, in most languages that have them, they do).
- slashnull 11y agoHa! 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.
- tel 11y agovariance 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.