[Haskell-cafe] Tree Semantics and efficiency

Conal Elliott conal at conal.net
Sat Jun 20 14:04:37 EDT 2009

Moreover, copying is not even meaningful in a functional setting.  A data
structure is indistinguishable from a copy of the data structure.  In
languages that allow mutation of data, one has to carefully copy data to
avoid accidental mutation by other computations.  Disallow data mutation,
and the problem disappears.

  - Conal

On Wed, Jun 17, 2009 at 7:44 AM, Jake McArthur <jake.mcarthur at gmail.com>wrote:

> Rouan van Dalen wrote:
>> It is important to store only a reference to the parent and not a copy of
>> the entire parent for efficiency.
> Others have already recommended the rosezipper package, which gives you
> what you want, but I want to address one thing.
>    foo = <stuff>
>    bar = foo
> In most implementations (including GHC, which I assume you are using),
> `bar` will *not* be an actual copy of `foo`. In fact, GHC will not make a
> deep copy of a structure unless you pattern match all the way down and
> reconstruct it all the way back up yourself.
> If you use a zipper, like Data.Tree.Zipper mentioned already, moving around
> will not create and destroy tons of data. It will only create and destroy
> the spine of the tree local to the current "pointer" into the tree, which is
> not a lot of data. If you are holding on to older versions of the zipper, of
> course, they won't even be destroyed.
> - Jake
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090620/b1b8485c/attachment.html

More information about the Haskell-Cafe mailing list