A zipper for Data.Tree.

- data Tree a = Node {}
- data Location a
- toLocation :: Tree a -> Location a
- fromLocation :: Location a -> Tree a
- dfsFold :: (w -> v -> w) -> w -> Tree v -> Tree w
- dfsFoldM :: Monad m => (w -> v -> m w) -> w -> Tree v -> m (Tree w)
- showTree :: Show a => Tree a -> String
- empty :: a -> Tree a
- up :: Location a -> Location a
- down :: Location a -> Location a
- left :: Location a -> Location a
- right :: Location a -> Location a
- replace :: Location a -> Tree a -> Location a
- change :: Location a -> a -> Location a
- insertDown :: Location a -> Tree a -> Location a
- insertLeft :: Location a -> Tree a -> Location a
- insertRight :: Location a -> Tree a -> Location a
- isTop :: Location a -> Bool
- isChild :: Location a -> Bool
- getValue :: Location a -> a
- subTree :: Location a -> Tree a
- top :: Location a -> Location a
- canGoLeft :: Location a -> Bool
- canGoRight :: Location a -> Bool
- canGoUp :: Location a -> Bool
- canGoDown :: Location a -> Bool
- type ZipperT v m a = StateT (Location v) m a
- nest :: Monad m => v -> ZipperT v m a -> ZipperT v m a
- getNode :: Monad m => ZipperT v m v
- setNode :: Monad m => v -> ZipperT v m ()
- runZipperT :: Monad m => ZipperT v m a -> Location v -> m (a, Tree v)
- evalZipperT :: Monad m => ZipperT v m a -> Location v -> m a
- execZipperT :: Monad m => ZipperT v m a -> Location v -> m (Tree v)
- shiftLeft :: Monad m => ZipperT v m ()
- shiftRight :: Monad m => ZipperT v m ()
- shiftLeft' :: Monad m => ZipperT v m ()
- shiftRight' :: Monad m => ZipperT v m ()
- withCurrentChild :: Monad m => ZipperT v m a -> ZipperT v m a

# Functional zipper

These are the core zipper functions.

data Tree a

Multi-way trees, also known as *rose trees*.

toLocation :: Tree a -> Location aSource

fromLocation :: Location a -> Tree aSource

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.

insertDown :: Location a -> Tree a -> Location aSource

insertLeft :: Location a -> Tree a -> Location aSource

insertRight :: Location a -> Tree a -> Location aSource

top :: Location a -> Location aSource

Traverses to the top of the tree.

up.top = undefined top.top = top

canGoRight :: Location a -> BoolSource

# 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.

:: 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.

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

shiftRight :: Monad m => ZipperT v m ()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.