-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Generic zipper implementation for Data.Tree
--   
--   A Haskell datastructure for working with locations in trees or
--   forests.
@package rosezipper
@version 0.2

module Data.Tree.Zipper

-- | A position within a Tree. The parameter t inidcates if
--   the position is pointing to a specific tree (if t is
--   Full), or if it is pointing in-between trees (if t is
--   Empty).
data TreePos t a

-- | Positions may be either Full or Empty.
class PosType t

-- | Position which does not point to a tree (e.g., it is between two
--   trees).
data Empty a

-- | Position which points to a tree.
data Full a

-- | Siblings before this position, closest first.
before :: PosType t => TreePos t a -> Forest a

-- | Siblings after this position, closest first.
after :: PosType t => TreePos t a -> Forest a

-- | All trees at this location (i.e., the current tree---if any---and its
--   siblings).
forest :: PosType t => TreePos t a -> Forest a

-- | The selected tree.
tree :: TreePos Full a -> Tree a

-- | The current label.
label :: TreePos Full a -> a

-- | The contexts of the parents for this position.
parents :: PosType t => TreePos t a -> [(Forest a, a, Forest a)]

-- | A location corresponding to the root of the given tree.
fromTree :: Tree a -> TreePos Full a

-- | The location at the beginning of the forest.
fromForest :: Forest a -> TreePos Empty a

-- | The forest containing this location.
toForest :: PosType t => TreePos t a -> Forest a

-- | The tree containing this location.
toTree :: TreePos Full a -> Tree a

-- | The parent of the given location.
parent :: PosType t => TreePos t a -> Maybe (TreePos Full a)

-- | The top-most parent of the given location.
root :: TreePos Full a -> TreePos Full a

-- | The space immediately before this location.
prevSpace :: TreePos Full a -> TreePos Empty a

-- | The tree before this location, if any.
prevTree :: TreePos Empty a -> Maybe (TreePos Full a)

-- | The sibling before this location.
prev :: PosType t => TreePos t a -> Maybe (TreePos t a)

-- | The first space in the current forest.
first :: TreePos Empty a -> TreePos Empty a

-- | The empty space at the given index. The first space is at index 0. For
--   indexes that are negative or too large, we return the first and last
--   position in the tree, respectively.
spaceAt :: Int -> TreePos Empty a -> TreePos Empty a

-- | The space immediately after this location.
nextSpace :: TreePos Full a -> TreePos Empty a

-- | The tree after this location, if any.
nextTree :: TreePos Empty a -> Maybe (TreePos Full a)

-- | The sibling after this location.
next :: PosType t => TreePos t a -> Maybe (TreePos t a)

-- | The last space in the current forest.
last :: TreePos Empty a -> TreePos Empty a

-- | The location at the beginning of the forest of children.
children :: TreePos Full a -> TreePos Empty a

-- | The first child of the given location.
firstChild :: TreePos Full a -> Maybe (TreePos Full a)

-- | The last child of the given location.
lastChild :: TreePos Full a -> Maybe (TreePos Full a)

-- | The child at the given index in the tree. The first child is at index
--   0.
childAt :: Int -> TreePos Full a -> Maybe (TreePos Full a)

-- | Are we at the top of the tree?
isRoot :: PosType t => TreePos t a -> Bool

-- | Are we the first position (of its kind) in a forest.
isFirst :: PosType t => TreePos t a -> Bool

-- | Are we the last position (of its kind) in a forest.
isLast :: PosType t => TreePos t a -> Bool

-- | Are we at the bottom of the tree?
isLeaf :: TreePos Full a -> Bool

-- | Do we have a parent?
isContained :: PosType t => TreePos t a -> Bool

-- | Do we have children?
hasChildren :: TreePos Full a -> Bool

-- | Insert a new tree at the current position.
insert :: Tree a -> TreePos Empty a -> TreePos Full a

-- | Remove the tree at the current position.
delete :: TreePos Full a -> TreePos Empty a

-- | Change the current tree.
setTree :: Tree a -> TreePos Full a -> TreePos Full a

-- | Modify the current tree.
modifyTree :: (Tree a -> Tree a) -> TreePos Full a -> TreePos Full a

-- | Modify the label at the current node.
modifyLabel :: (a -> a) -> TreePos Full a -> TreePos Full a

-- | Change the label at the current node.
setLabel :: a -> TreePos Full a -> TreePos Full a
instance (Read a, Read (t a)) => Read (TreePos t a)
instance (Show a, Show (t a)) => Show (TreePos t a)
instance (Eq a, Eq (t a)) => Eq (TreePos t a)
instance Read (Empty a)
instance Show (Empty a)
instance Eq (Empty a)
instance Read a => Read (Full a)
instance Show a => Show (Full a)
instance Eq a => Eq (Full a)
instance PosType Empty
instance PosType Full
