[Haskell-cafe] [Newbie] Quest for inheritance

ChrisRathman.6155983 at bloglines.com ChrisRathman.6155983 at bloglines.com
Mon Jun 6 13:09:56 EDT 2005


--- Cédric Paternotte <cpaternotte at gmail.com 
> 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 ?

The Haskell shapes example
was a recreational activity that started with Jim Weirich's challenge at:
http://onestepback.org/articles/poly/

As Jim notes, inheritance was not
the point of the exercise.  And the Haskell example I did was somewhere in
the middle of 56 other languages I had been tinkering with: http://www.angelfire.com/tx4/cus/shapes/index.html


In most of the OOP languages, we tried to use code inheritance if it was
available, but where it was not obvious or easily achievable (Erlang, Mercury,
Clean, Haskell), it was bypassed.  I did spend a bit of time trying to figure
out how to get subtype polymorphism to work in Haskell, but in terms of my
familiarity with the language, I am by no means proficient with the language.


Best to ask Ralf about the more involed stuff.  :-)

> 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
;) 

Subtypes may share some common behavior but from a top level perspective,
a Rectangle type is not the same as a Circle type.  Existential types allow
you to treat the different types via the common behavior defined in the parent
type.  Without existential types, you can have only monomorphic collections.


Chris Rathman


More information about the Haskell-Cafe mailing list