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

Bulat Ziganshin bulat.ziganshin at gmail.com
Sun Jun 3 04:14:53 EDT 2007

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 same applies to updating nested structures. you just return
updated structure on each level of processing

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list