
Hi Chris,
On 6 Jun 2005 14:53:11 -0000, ChrisRathman.6155983@bloglines.com
The differences in the two shape examples doesn't have to do with code inheritance - it has to do with subtype polymorphism.
Does this mean that I was wrong in saying in my initial post that existential types can be used to get "code inheritance" ? Or is it just that the Shapes example has never been meant to illustrate that side of things ?
Existential types allow you to throw different subtypes into a collection and have the function dispatch on the common superclass type. The example without existential types demonstrates parametric polymorphism, but not subclass polymorphism.
Okay, I think I've finally spotted the difference : Using existential types you actually managed to put both CircleInstance and RectangleInstance in the same list. I didn't notice that detail at first. All the difference lies in that line ;) So I understand this is something you obviously cannot do when using classic subtyping. Incredible. This is weird, I mean that's the kind of feature I would take for granted. That makes existential types much more useful indeed. Even essential I would say.
As far as inheritance, there's actually two kinds that occur in most OO languages. The first being type inheritance (which really just gets you subtype polymorphism). And then there's code inheritance - which is what you are trying to achieve.
Thanks for the clarification.
At any rate, I consider inheritance to be a convenience mechanism, and not vitally necessary to the concepts of encapsulation, type inheritance, and polymorphism, though I realize that many do consider it important.
Well, on the -way too big for my head- projects I'm working on, inheritance saves my life many times a day.
Chris Rathman
Thanks for a lot for your time Chris, think I'm slowly starting to get the picture of all this. Cédric