WebBits-0.9.3: JavaScript analysis tools

WebBits.Data.Zipper

Contents

Description

A zipper for Data.Tree.

Synopsis

Functional zipper

These are the core zipper functions.

data Tree a

Multi-way trees, also known as rose trees.

Constructors

Node 

Fields

rootLabel :: a

label value

subForest :: Forest a

zero or more child trees

dfsFoldSource

Arguments

:: (w -> v -> w)

transforms a node v using the accumulated value w from the root of the tree to v

-> w

the initial value of the accumulator at the root

-> Tree v 
-> Tree w 

dfsFoldM :: Monad m => (w -> v -> m w) -> w -> Tree v -> m (Tree w)Source

Similar to dfsFold, but the transformation is done in the monad m. The sequence of operations is depth-first, left-to-right.

empty :: a -> Tree aSource

top :: Location a -> Location aSource

Traverses to the top of the tree.

 up.top = undefined
 top.top = top

Imperative tree construction

A state monad that carries a zipper. It provides convenient methods to imperatively create and update a tree.

The state monad's set method may be used to arbitrarily update the current location. However, such updates can break the behavior of nest and withCurrentChild. We recommend avoiding StateT.set.

type ZipperT v m a = StateT (Location v) m aSource

nestSource

Arguments

:: Monad m 
=> v

value of the new right-most child

-> ZipperT v m a

computation applied to the new child

-> ZipperT v m a

returns the result of the nested computation

Creates a new node as the right-most child of the current node.

setNode :: Monad m => v -> ZipperT v m ()Source

runZipperT :: Monad m => ZipperT v m a -> Location v -> m (a, Tree v)Source

evalZipperT :: Monad m => ZipperT v m a -> Location v -> m aSource

execZipperT :: Monad m => ZipperT v m a -> Location v -> m (Tree v)Source

shiftLeft' :: Monad m => ZipperT v m ()Source

Silently fails to shift left if there is no left-child.

shiftRight' :: Monad m => ZipperT v m ()Source

Silently fails to shift right if there is no right-child.

withCurrentChildSource

Arguments

:: Monad m 
=> ZipperT v m a

computation to apply to the current child

-> ZipperT v m a

returns the result of the nested computation