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
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
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
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
[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