4 ms·
I disagree. The problem is with the difference between a source and a sink not being represented in the type system. With that difference represented properly,
by TheCoelacanth 8y ago
I disagree. The problem is with the difference between a source and a sink not being represented in the type system. With that difference represented properly, variance becomes very simple. A source is covariant, a sink is contravariant and something that is both a source and a sink is invariant. That is slightly harder for the language designer but much easier for the user.
- munificent 8y agoThat covers many cases, but not all. Consider: bool contains(other) { ... } This looks like a sink operation — you're passing a value in, just like you do with add() — but is naturally covariant, not contravariant.
- TheCoelacanth 8y agoThat's a source operation. You aren't putting values into the collection, you are examining values in the collection.
- munificent 8y agoYes, except the type argument appears in parameter position, which is typically contravariant.
- TheCoelacanth 8y agoOkay, but it's not. Make source vs. sink explicit and it will be obvious because the method will be defined on source and not on sink.