[Haskell-cafe] Growing Trees

2005-09-22 Thread Tom Hawkins
I'm porting an ML program to Haskell, but am having difficulty with particular data structure: a tree where each node has references to the children as well as the parent... data Tree a = TreeRoot { stuff:: a , children :: [Tree] } | TreeNode { stuff:: a

Re: [Haskell-cafe] Growing Trees

2005-09-22 Thread robert dockins
It sounds like you are porting an algorithm which does destructive updates on this tree. If so, you can use the ST (or IO) monad and use STRef (IORef). data Tree a = TreeRoot { stuff:: STRef a , children :: STRef [Tree] } . you would get at the data

Re: [Haskell-cafe] Growing Trees

2005-09-22 Thread Sebastian Sylvan
On 9/22/05, Tom Hawkins [EMAIL PROTECTED] wrote: I'm porting an ML program to Haskell, but am having difficulty with particular data structure: a tree where each node has references to the children as well as the parent... data Tree a = TreeRoot { stuff:: a , children

Re: [Haskell-cafe] Growing Trees

2005-09-22 Thread Tom Hawkins
robert dockins wrote: It sounds like you are porting an algorithm which does destructive updates on this tree. Yes, parent and children were mutable fields. If so, you can use the ST (or IO) monad and use STRef (IORef). data Tree a = TreeRoot { stuff:: STRef a , children

Re: [Haskell-cafe] Growing Trees

2005-09-22 Thread Ben Rudiak-Gould
[Previously sent only to the OP -- oops] Tom Hawkins wrote: data Tree a = TreeRoot { stuff:: a , children :: [Tree] } | TreeNode { stuff:: a , parent :: Tree , children :: [Tree] } But because of these bidirectional