A class for tree types and representations of selections on tree types, as well as functions for converting between text and tree selections.

- type Path = [Int]
- root :: Path
- type Nav = Path -> Path
- up :: Nav
- into :: Int -> Nav
- down :: Nav
- left :: Nav
- right :: Nav
- sibling :: Int -> Nav
- class Tree p where
- children :: p -> [p]

- depth :: Tree t => t -> Int
- selectDepth :: Tree t => Int -> t -> [t]
- flatten :: Tree t => t -> [t]
- follow :: (Monad m, Tree t) => t -> Path -> m t
- child :: (Monad m, Tree t) => t -> Int -> m t
- class Tree t => Selectable t where
- allowSubranges :: t -> Bool

- type TreeSelection = (Path, Int)
- select :: (Monad m, Tree t) => t -> TreeSelection -> m [t]
- allSelections :: Selectable a => a -> [TreeSelection]
- selectionToRange :: (Monad m, Tree a, Ranged a) => a -> TreeSelection -> m Range
- rangeToSelection :: (Monad m, Selectable a, Ranged a) => a -> Range -> m TreeSelection
- posToPath :: (Monad m, Tree a, Ranged a) => a -> Pos -> m Path
- isValidRange :: (Ranged a, Selectable a) => a -> Range -> Bool
- suggestBy :: (Selectable a, Ranged a) => (Range -> Range -> Int) -> a -> Range -> [TreeSelection]
- suggest :: (Selectable a, Ranged a) => a -> Range -> [TreeSelection]
- repairBy :: (Ranged a, Selectable a) => (Range -> Range -> Int) -> a -> Range -> Range
- repair :: (Ranged a, Selectable a) => a -> Range -> Range

# Paths and navigation

A path in a tree. Each integer denotes the selection of a child; these indices are 0-relative.

Move down into the nth child node. If `n`

is negative, the leftmost child is selected.

Move `n`

siblings to the right. `n`

can be negative. If the new child index becomes negative, the leftmost child is selected.

# Tree types

Tree types.

selectDepth :: Tree t => Int -> t -> [t]Source

Yields all ancestors at the specified depth.

follow :: (Monad m, Tree t) => t -> Path -> m tSource

Follows a path in a tree, returning the result in a monad.

# Tree selections

class Tree t => Selectable t whereSource

Selectable trees.

allowSubranges :: t -> BoolSource

Tells whether complete subranges of children may be selected in this tree node. If not, valid TreeSelections in this tree always have a second element `0`

.

type TreeSelection = (Path, Int)Source

Selection in a tree. The path indicates the left side of the selection; the int tells how many siblings to the right are included in the selection.

select :: (Monad m, Tree t) => t -> TreeSelection -> m [t]Source

Selects part of a tree.

allSelections :: Selectable a => a -> [TreeSelection]Source

Enumerates all possible selections of a tree.

selectionToRange :: (Monad m, Tree a, Ranged a) => a -> TreeSelection -> m RangeSource

Computes the range of a valid selection.

rangeToSelection :: (Monad m, Selectable a, Ranged a) => a -> Range -> m TreeSelectionSource

Converts a specified range to a corresponding selection and returns it in a monad.

posToPath :: (Monad m, Tree a, Ranged a) => a -> Pos -> m PathSource

Returns the path to the deepest descendant whose range contains the specified position.

isValidRange :: (Ranged a, Selectable a) => a -> Range -> BoolSource

Tells whether the text selection corresponds to a tree selection.

# Suggesting and fixing

suggestBy :: (Selectable a, Ranged a) => (Range -> Range -> Int) -> a -> Range -> [TreeSelection]Source

Yields all possible selections, ordered by distance to the specified range, closest first.

suggest :: (Selectable a, Ranged a) => a -> Range -> [TreeSelection]Source

`suggest`

uses `distRange`

as cost function.