containers-0.5.6.2: Assorted concrete container types

Copyright (c) The University of Glasgow 2002 BSD-style (see the file libraries/base/LICENSE) libraries@haskell.org experimental portable Trustworthy Haskell98

Data.Tree

Description

Multi-way trees (aka rose trees) and forests.

Synopsis

Documentation

data Tree a Source

Multi-way trees, also known as rose trees.

Constructors

 Node FieldsrootLabel :: alabel valuesubForest :: Forest azero or more child trees

Instances

 Source Source Source Source Source Eq a => Eq (Tree a) Source Data a => Data (Tree a) Source Read a => Read (Tree a) Source Show a => Show (Tree a) Source NFData a => NFData (Tree a) Source

type Forest a = [Tree a] Source

Two-dimensional drawing

Neat 2-dimensional drawing of a tree.

Neat 2-dimensional drawing of a forest.

Extraction

flatten :: Tree a -> [a] Source

The elements of a tree in pre-order.

levels :: Tree a -> [[a]] Source

Lists of nodes at each level of the tree.

Building trees

unfoldTree :: (b -> (a, [b])) -> b -> Tree a Source

Build a tree from a seed value

unfoldForest :: (b -> (a, [b])) -> [b] -> Forest a Source

Build a forest from a list of seed values

unfoldTreeM :: Monad m => (b -> m (a, [b])) -> b -> m (Tree a) Source

Monadic tree builder, in depth-first order

unfoldForestM :: Monad m => (b -> m (a, [b])) -> [b] -> m (Forest a) Source

Monadic forest builder, in depth-first order

unfoldTreeM_BF :: Monad m => (b -> m (a, [b])) -> b -> m (Tree a) Source

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) Source

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.