WebBits-0.9.2: JavaScript analysis toolsSource codeContentsIndex
WebBits.Data.Zipper
Contents
Functional zipper
Imperative tree construction
Description
A zipper for Data.Tree.
Synopsis
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 Location a Source
toLocation :: Tree a -> Location aSource
fromLocation :: Location a -> Tree aSource
dfsFoldSource
::
=> w -> v -> wtransforms a node v using the accumulated value w from the root of the tree to v
-> wthe 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.
showTree :: Show a => Tree a -> StringSource
empty :: a -> Tree aSource
up :: Location a -> Location aSource
down :: Location a -> Location aSource
left :: Location a -> Location aSource
right :: Location a -> Location aSource
replace :: Location a -> Tree a -> Location aSource
change :: Location a -> a -> Location aSource
insertDown :: Location a -> Tree a -> Location aSource
insertLeft :: Location a -> Tree a -> Location aSource
insertRight :: Location a -> Tree a -> Location aSource
isTop :: Location a -> BoolSource
isChild :: Location a -> BoolSource
getValue :: Location a -> aSource
subTree :: Location a -> Tree aSource
top :: Location a -> Location aSource

Traverses to the top of the tree.

 up.top = undefined
 top.top = top
canGoLeft :: Location a -> BoolSource
canGoRight :: Location a -> BoolSource
canGoUp :: Location a -> BoolSource
canGoDown :: 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.

type ZipperT v m a = StateT (Location v) m aSource
nestSource
:: Monad m
=> vvalue of the new right-most child
-> ZipperT v m acomputation applied to the new child
-> ZipperT v m areturns the result of the nested computation
Creates a new node as the right-most child of the current node.
getNode :: Monad m => ZipperT v m vSource
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
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.
withCurrentChildSource
:: Monad m
=> ZipperT v m acomputation to apply to the current child
-> ZipperT v m areturns the result of the nested computation
Produced by Haddock version 2.3.0