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

Phlex Phlex at telenet.be
Sun Jun 3 04:34:26 EDT 2007

Bulat Ziganshin wrote:
> Hello Phlex,
> Sunday, June 3, 2007, 11:41:29 AM, you wrote:
>> That's precisely the thing i don't understand.
>> In order to update node 3 with a new pointer, i need to mutate it, so i
>> need to recreate it, and so on up to node 1.
> yes, that's true
>> Now in this exemple, it's ok since that's a regular tree and the process
>> can be automated, but when each node has a different type, it can become
>> quite hairy.
> may be all that you need is structure update syntax?
> data Planet = Planet { age :: Double
>                      , weight :: Double
>                      .....
>                      }
> updatePlanet p = p {age=(age p)*2}

The thing is, now that i have my planet p... i want to change it's age 
... and get back the new state of the universe...

So i need to do something like this :

changePlanetAge universe galaxy planet age = ...lots of code, returning 
a new universe
And the same code for all functions updating any of the properties of my 
planet ...
And the same code for all functions updating properties of a country on 
this planet...

while in the OO paradigm, i only need to do

changlePlanetAge planet age = ...just what you wrote

I understand that the advantages of functional programming do come at a 
cost ... And i'm pretty sure you guys came up with some way to avoid 
expressing all that upward copying, although it must happen somehow.

I'm not sure i'm being clear here.


More information about the Haskell-Cafe mailing list