[Haskell-cafe] Tree Guidance

Hans van Thiel hthiel.char at zonnet.nl
Tue Jun 26 09:04:00 EDT 2007

Hello All,

Both CFP and SOE have chapters on trees and there is a standard library
Data.Tree. I expected to find all kinds of functions there, as in
Data.List, but instead the functions are defined as instances of more
general structures. It uses:

import Control.Applicative (Applicative(..), (<$>))
import Control.Monad
import Data.Monoid (Monoid(..))
import Data.Sequence (Seq, empty, singleton, (<|), (|>), fromList,
			ViewL(..), ViewR(..), viewl, viewr)
import Data.Foldable (Foldable(foldMap), toList)
import Data.Traversable (Traversable(traverse))
import Data.Typeable

When looking at those it is not clear (to me) what those all mean and I
have not been able to find much on the WiKi either.

Could someone with more experience provide some guidance on how to learn
to use these libraries (and ultimately on the tree type in Data.Tree,
which is what I want).

There is a Zipper Monad with defined functions, which look promising,
but I have not heard of this before, and it appears not to be standard.

Does anybody have any experience with these libraries they could share?

Ideally I would want a N-ary tree, where the branches are what's
actually the represented data, and so I would like to access it both
from the root and the leaves. In an imperative language I would just add
an up-pointer in each node, but I have no idea how expensive this would
be in Haskell, or if it's necessary at all.

Many thanks for your help,

Hans van Thiel

More information about the Haskell-Cafe mailing list