[Haskell-cafe] Growing Trees

Tom Hawkins tom at confluent.org
Thu Sep 22 15:55:40 EDT 2005

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
              , parent   :: Tree
              , children :: [Tree]

But because of these bidirectional links, every time I add a node I must 
reconstructing the entire tree.  There is also the add coding complexity 
of threading the tree through various functions to simulate state.

What are my [monadic] options?


More information about the Haskell-Cafe mailing list