Tree.md

September 19, 2015 ยท View on GitHub

Module Data.Tree

Tree

data Tree a

An abstract tree type

Instances
instance showTree :: (Show a) => Show (Tree a)
instance eqTree :: (Eq a) => Eq (Tree a)
instance functorTree :: Functor Tree
instance applyTree :: Apply Tree
instance applicativeTree :: Applicative Tree
instance bindTree :: Bind Tree
instance monadTree :: Monad Tree
instance foldableTree :: Foldable Tree
instance traversableTree :: Traversable Tree

View

data View f a
  = View a (Array (f a))

A view which is used to construct and destruct the tree. This type is a pattern functor/signature, where f represents the recursive structure.

out

out :: forall a. Tree a -> View Tree a

Pattern match on a tree. Example:

case out t of
  View a ts -> ...

into

into :: forall a. View Tree a -> Tree a

Construct a tree from a tree pattern/view. Example:

tree :: Tree Int
tree = into $ View 0 []

transView

transView :: forall f g a. (forall b. f b -> g b) -> View f a -> View g a

Map a tree across a natural transformation.

flatten

flatten :: forall a. Tree a -> NonEmpty Array a