Re: [Haskell-cafe] Tree Semantics and efficiency

2009-06-20 Thread Conal Elliott
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

[Haskell-cafe] Tree Semantics and efficiency

2009-06-17 Thread Rouan van Dalen
Hi everyone. I would like to confirm the following semantics. I want a tree which can be traversed both downwards and upwards. To do this i need to store the following for each node: o) a reference to the parent node (so we can traverse up the tree). This must be a reference as i dont want

Re: [Haskell-cafe] Tree Semantics and efficiency

2009-06-17 Thread Miguel Mitrofanov
You can use the standart tying the knot-technique. For example: data Tree = TreeNode String (Maybe Tree) [Tree] -- what's the parent of the root node? test :: Tree test = let parent = TreeNode I'm parent Nothing [child1, child2] child1 = TreeNode I'm child1 (Just parent) []

Re: [Haskell-cafe] Tree Semantics and efficiency

2009-06-17 Thread Antoine Latter
On Wed, Jun 17, 2009 at 9:24 AM, Miguel Mitrofanovmiguelim...@yandex.ru wrote: You can use the standart tying the knot-technique. For example: data Tree = TreeNode String (Maybe Tree) [Tree] -- what's the parent of the root node? test :: Tree test =   let parent = TreeNode I'm parent

Re: [Haskell-cafe] Tree Semantics and efficiency

2009-06-17 Thread Jake McArthur
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