RE: [Haskell-cafe] [Newbie] Quest for inheritance

Hi Gracjan,
http://homepages.cwi.nl/~ralf/OOHaskell/src/PoorMens2/ (again *not* using OOHaskell)
From the quick skim of code: .?. -- apply function to upcast object .!. -- apply modification function to upcast object and substitute returned value (new object), basically update
Absolutely.
Is there any description avaliable what is PoorMens2 all about?
Let me try. It's just a variation on Chris' encoding of the shape example, while trying to improve code reuse, while trying to highlight the commonalities in the data parts of the objects in the inheritance hierarchy. The approach ends up being similar to yours in so far that getters (and setters) can be made work for derived types once they are defined on the base type. I just notice that there is a short (because non-monadic) version: http://homepages.cwi.nl/~ralf/OOHaskell/src/PoorMens/ Ralf

I just notice that there is a short (because non-monadic) version:
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 ? Cédric
participants (2)
-
Cédric Paternotte
-
Ralf Lammel