Re:Covariance and Contravariance: a fresh look at an old iss...
by shiro on Wednesday May 18, 2016 @12:51PM
(#11723320)
Ah, ok, I mixed up you with continuational.
For this context, what I'm saying is that if you don't need to extract an apple from a list of fruits, then you can do it safely with inheritance, so whether using inheritance or delegation is irrelevant. Isn't it?
Re:Covariance and Contravariance: a fresh look at an old iss...
by catnaroek on Wednesday May 18, 2016 @03:30PM
(#11725036)
If you want to extract an apple from a list of fruits, you need runtime type information (so that you can test whether a particular fruit object happens to be an apple), which has nothing to do with whether your language has inheritance or not. Using runtime type information is a symptom of bad design, though, since it lessens the extent to which you can reason about programs (as pieces of text) by just looking at their types.
FWIW, I didn't propose the original Scala snippet, so it isn't really “my” solution.
> the original covariance/contravariance problem
The problem is precisely preventing what you're trying to do, because it's unsafe.