Donald Bruce Stewart wrote:
Phlex:
On the other side, using the functional paradigm, it seems to me that the function i use in order to create a _new_ inhabitant with a different age will need to have knowledge of the country over it, the planet ..and so on up to the universe...as i need to update all these structures to reflect the change. This is pretty bad and most probably doesn't need to be like this.
Nope, its not done like that. You share as much of the original
structure as you can, as a general principle.

Imagine updating a node in a tree by just detaching and reattaching a
pointer.

    [1]                         [1]
    / \                         / \
[2] [3] update node 5 [2] [3] / \ with value 7 / \
     [4] [5]                     [4] *

and share the rest of the structure. Since the rest isn't mutable
anyway, you can share all over.

-- Don

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.

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.

Sacha

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to