Haskell Hierarchical Libraries (base package)ContentsIndex
Data.Tree
Portabilityportable
Stabilityexperimental
Maintainerlibraries@haskell.org
Contents
Two-dimensional drawing
Extraction
Building trees
Description
Multi-way trees (aka rose trees) and forests.
Synopsis
data Tree a = Node {
rootLabel :: a
subForest :: (Forest a)
}
type Forest a = [Tree a]
drawTree :: Tree String -> String
drawForest :: Forest String -> String
flatten :: Tree a -> [a]
levels :: Tree a -> [[a]]
unfoldTree :: (b -> (a, [b])) -> b -> Tree a
unfoldForest :: (b -> (a, [b])) -> [b] -> Forest a
unfoldTreeM :: Monad m => (b -> m (a, [b])) -> b -> m (Tree a)
unfoldForestM :: Monad m => (b -> m (a, [b])) -> [b] -> m (Forest a)
unfoldTreeM_BF :: Monad m => (b -> m (a, [b])) -> b -> m (Tree a)
unfoldForestM_BF :: Monad m => (b -> m (a, [b])) -> [b] -> m (Forest a)
Documentation
data Tree a
Multi-way trees, also known as rose trees.
Constructors
Node
rootLabel :: alabel value
subForest :: (Forest a)zero or more child trees
show/hide Instances
Functor Tree
Eq a => Eq (Tree a)
Read a => Read (Tree a)
Show a => Show (Tree a)
type Forest a = [Tree a]
Two-dimensional drawing
drawTree :: Tree String -> String
Neat 2-dimensional drawing of a tree.
drawForest :: Forest String -> String
Neat 2-dimensional drawing of a forest.
Extraction
flatten :: Tree a -> [a]
The elements of a tree in pre-order.
levels :: Tree a -> [[a]]
Lists of nodes at each level of the tree.
Building trees
unfoldTree :: (b -> (a, [b])) -> b -> Tree a
Build a tree from a seed value
unfoldForest :: (b -> (a, [b])) -> [b] -> Forest a
Build a forest from a list of seed values
unfoldTreeM :: Monad m => (b -> m (a, [b])) -> b -> m (Tree a)
Monadic tree builder, in depth-first order
unfoldForestM :: Monad m => (b -> m (a, [b])) -> [b] -> m (Forest a)
Monadic forest builder, in depth-first order
unfoldTreeM_BF :: Monad m => (b -> m (a, [b])) -> b -> m (Tree a)
Monadic tree builder, in breadth-first order, using an algorithm adapted from Breadth-First Numbering: Lessons from a Small Exercise in Algorithm Design, by Chris Okasaki, ICFP'00.
unfoldForestM_BF :: Monad m => (b -> m (a, [b])) -> [b] -> m (Forest a)
Monadic forest builder, in breadth-first order, using an algorithm adapted from Breadth-First Numbering: Lessons from a Small Exercise in Algorithm Design, by Chris Okasaki, ICFP'00.
Produced by Haddock version 0.7