3 ms·
Interfaces have variance too, as long as they give rise to a subtyping relationship (which, in most languages that have them, they do).
by pcwalton 11y ago
Interfaces 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.