4 ms·
I didn't really think about variance while writing the examples; I assumed it would just work the way it does in Scala and Kotlin (explicit variance annotations
by ar-nelson 6y ago
I didn't really think about variance while writing the examples; I assumed it would just work the way it does in Scala and Kotlin (explicit variance annotations). I do wonder if that's necessary, though--in theory, the compiler could infer variance from how you use the type parameters, which is in a similar spirit to the rest of the language.
What do you think are the major problems with variance in OO?
- howinteresting 6y agoExplicit variance, especially for types, is just really confusing. Implicit variance has the risk of breaking APIs or overpromising a particular variance without developers realizing. If you have subtyping you need to think about variance. That's led me to believe that subtyping's simplicity is deceptive, and that it should be avoided as much as possible. (Rust has subtyping but only for lifetimes, and it's confusing enough there.)