[Haskell-cafe] [Newbie] Quest for inheritance

Cédric Paternotte cpaternotte at gmail.com
Tue Jun 7 06:50:21 EDT 2005

> I just notice that there is a short (because non-monadic) version:
> http://homepages.cwi.nl/~ralf/OOHaskell/src/PoorMens/

I have to say that this version of the Shape example is my favourite so far.
Good compromise between complexity, typing and usefulness.

May I just suggest an improvement that could further improve the code re-use ?

I noticed that both Rectangle and Circle need to redefine the
operators because of the different names of their respective delegate
to Shape, namely rectangle2shape and circle2shape.

I we were to give these fields the same name ('parent', or 'super') in
both Rectangle and Circle, could it be that we can avoid to redefine
the operators by moving their definition upwards (and thus requiring
only one definition for both classes) ?

I guess that would also mean that we restrict ourselves to
single-inheritance since we rely on the uniqueness of the name
'parent' throughout. But since single inheritance is IMO enough to fit
most needs I don't see it as a problem.

Would it then be a problem if we further subclass Rectangle in, say,
two subclasses Square and NonSquareRectangle ? Would that still work
or would there be a collision between the multiple 'parent' fields ?


More information about the Haskell-Cafe mailing list