News for hackers. Stuff that matters.
Re:Covariance and Contravariance: a fresh look at an old iss... by jayd16 on Tuesday May 17, 2016 @05:24PM (#11717569)
Simple things like adding a list of Apples to a list of Fruits become non-trivial.
Re:Covariance and Contravariance: a fresh look at an old iss... by continuational on Tuesday May 17, 2016 @06:08PM (#11717925)
Non-trivial? In Scala it would be:

    fruits ++= apples.map(_.asFruit)
Re:Covariance and Contravariance: a fresh look at an old iss... by shiro on Tuesday May 17, 2016 @07:35PM (#11718515)
That part is fine. The difficulty arises when you want to take out an apple from a list of fruits.
Re:Covariance and Contravariance: a fresh look at an old iss... by catnaroek on Tuesday May 17, 2016 @09:48PM (#11719156)
Why should you be able to do that?
Re:Covariance and Contravariance: a fresh look at an old iss... by shiro on Tuesday May 17, 2016 @11:31PM (#11719524)
Right, if you take type-safety first, you shouldn't be able to. But a list of abstract fruits has very limited usage without the ability to accessing concrete fruit instance. The adoption of downcasting in some OO languages came out from such needs, given that they lacked generic and/or algebraic types. And with that regard, I thought your solution didn't address the original covariance/contravariance problem (that is, want to have heterogeneous list of fruits and allowing to access concrete types of individual elements).

There are type-safe ways, like making a fruit a sum type of apple and banana, or using traits or type classes, etc. But is-a/has-a discussion seems a bit off from that.

Re:Covariance and Contravariance: a fresh look at an old iss... by catnaroek on Wednesday May 18, 2016 @10:59AM (#11722424)
> I thought your solution didn't address

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.

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.
Re:Covariance and Contravariance: a fresh look at an old iss... by shiro on Thursday May 19, 2016 @06:22AM (#11729152)
I agree with you all. All I say is that suggesting delegation in place of inheritance to address contravariance issue seems off the mark.