[Haskell-cafe] I just don't get it (data structures and OO)

Ketil Malde ketil at ii.uib.no
Sun Jun 3 16:01:17 EDT 2007

On Sun, 2007-06-03 at 09:02 -0300, Felipe Almeida Lessa wrote:
> On 6/3/07, Tillmann Rendel <rendel at rbg.informatik.tu-darmstadt.de> wrote:
> > In functional programming, problems of the kind "and the same code for
> > all functions doing something related" are most often solved by
> > introducing higher order functions. Let's try to decompose the problem
> > as follows:

> Now I've got one question ;).  Is it *efficient* to go down this way?

Only one way to find out!

> Maybe using a Map instead of
> a list would at least let the complexity go down a little bit? Or am I
> missing something?

I was going to suggest that.  The difference - well, one of them -
between OOP and FP is that FP deals with values, OOP with data ojects.
The objects have identity, so you can change the name of a planet, and
maintain that it is still the same planet.  A value is just defined as
itself, and if you insist you can change a value, at least you must
admit it then becomes a different one.

Identity can be emulated by relatively straightforward means: store all
planets in a Map indexed by something that is useful as an identifier
(i.e. stays constant and is unique), and have a Galaxy keep a list of

You may even find that the dissociation of galaxies from planets etc is
an advantage, perhaps you want to deal with planets irrespectively of
their galaxies, or perhaps some planets don't even belong to a galaxy?


More information about the Haskell-Cafe mailing list