rosezipper-0.2: Generic zipper implementation for Data.Tree

Safe HaskellSafe
LanguageHaskell98

Data.Tree.Zipper

Contents

Synopsis

Documentation

data TreePos t a Source #

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

Instances

(Eq (t a), Eq a) => Eq (TreePos t a) Source # 

Methods

(==) :: TreePos t a -> TreePos t a -> Bool #

(/=) :: TreePos t a -> TreePos t a -> Bool #

(Read (t a), Read a) => Read (TreePos t a) Source # 
(Show (t a), Show a) => Show (TreePos t a) Source # 

Methods

showsPrec :: Int -> TreePos t a -> ShowS #

show :: TreePos t a -> String #

showList :: [TreePos t a] -> ShowS #

class PosType t Source #

Positions may be either Full or Empty.

Minimal complete definition

_prev, _next, _forest

data Empty a Source #

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

Instances

data Full a Source #

Position which points to a tree.

Instances

PosType Full Source # 
Eq a => Eq (Full a) Source # 

Methods

(==) :: Full a -> Full a -> Bool #

(/=) :: Full a -> Full a -> Bool #

Read a => Read (Full a) Source # 
Show a => Show (Full a) Source # 

Methods

showsPrec :: Int -> Full a -> ShowS #

show :: Full a -> String #

showList :: [Full a] -> ShowS #

Context

before :: PosType t => TreePos t a -> Forest a Source #

Siblings before this position, closest first.

after :: PosType t => TreePos t a -> Forest a Source #

Siblings after this position, closest first.

forest :: PosType t => TreePos t a -> Forest a Source #

All trees at this location (i.e., the current tree---if any---and its siblings).

tree :: TreePos Full a -> Tree a Source #

The selected tree.

label :: TreePos Full a -> a Source #

The current label.

parents :: PosType t => TreePos t a -> [(Forest a, a, Forest a)] Source #

The contexts of the parents for this position.

Conversions

fromTree :: Tree a -> TreePos Full a Source #

A location corresponding to the root of the given tree.

fromForest :: Forest a -> TreePos Empty a Source #

The location at the beginning of the forest.

toForest :: PosType t => TreePos t a -> Forest a Source #

The forest containing this location.

toTree :: TreePos Full a -> Tree a Source #

The tree containing this location.

Moving around

parent :: PosType t => TreePos t a -> Maybe (TreePos Full a) Source #

The parent of the given location.

root :: TreePos Full a -> TreePos Full a Source #

The top-most parent of the given location.

prevSpace :: TreePos Full a -> TreePos Empty a Source #

The space immediately before this location.

prevTree :: TreePos Empty a -> Maybe (TreePos Full a) Source #

The tree before this location, if any.

prev :: PosType t => TreePos t a -> Maybe (TreePos t a) Source #

The sibling before this location.

first :: TreePos Empty a -> TreePos Empty a Source #

The first space in the current forest.

spaceAt :: Int -> TreePos Empty a -> TreePos Empty a Source #

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.

nextSpace :: TreePos Full a -> TreePos Empty a Source #

The space immediately after this location.

nextTree :: TreePos Empty a -> Maybe (TreePos Full a) Source #

The tree after this location, if any.

next :: PosType t => TreePos t a -> Maybe (TreePos t a) Source #

The sibling after this location.

last :: TreePos Empty a -> TreePos Empty a Source #

The last space in the current forest.

children :: TreePos Full a -> TreePos Empty a Source #

The location at the beginning of the forest of children.

firstChild :: TreePos Full a -> Maybe (TreePos Full a) Source #

The first child of the given location.

lastChild :: TreePos Full a -> Maybe (TreePos Full a) Source #

The last child of the given location.

childAt :: Int -> TreePos Full a -> Maybe (TreePos Full a) Source #

The child at the given index in the tree. The first child is at index 0.

Node classification

isRoot :: PosType t => TreePos t a -> Bool Source #

Are we at the top of the tree?

isFirst :: PosType t => TreePos t a -> Bool Source #

Are we the first position (of its kind) in a forest.

isLast :: PosType t => TreePos t a -> Bool Source #

Are we the last position (of its kind) in a forest.

isLeaf :: TreePos Full a -> Bool Source #

Are we at the bottom of the tree?

isContained :: PosType t => TreePos t a -> Bool Source #

Do we have a parent?

hasChildren :: TreePos Full a -> Bool Source #

Do we have children?

Working with the current tree

insert :: Tree a -> TreePos Empty a -> TreePos Full a Source #

Insert a new tree at the current position.

delete :: TreePos Full a -> TreePos Empty a Source #

Remove the tree at the current position.

setTree :: Tree a -> TreePos Full a -> TreePos Full a Source #

Change the current tree.

modifyTree :: (Tree a -> Tree a) -> TreePos Full a -> TreePos Full a Source #

Modify the current tree.

modifyLabel :: (a -> a) -> TreePos Full a -> TreePos Full a Source #

Modify the label at the current node.

setLabel :: a -> TreePos Full a -> TreePos Full a Source #

Change the label at the current node.