data-named-0.4.0: Data types for named entities

Safe HaskellSafe-Inferred

Data.Named.Tree

Contents

Description

Working with NE trees and forests.

Synopsis

Auxiliary types

type NeTree a b = Tree (Either a b)Source

A tree with a values in internal nodes and b values in leaves.

type NeForest a b = Forest (Either a b)Source

A forest with a values in internal nodes and b values in leaves.

Span

data Span w Source

Spanning of a tree.

Constructors

Span 

Fields

beg :: w
 
end :: w
 

Instances

Eq w => Eq (Span w) 
(Eq (Span w), Ord w) => Ord (Span w) 
Show w => Show (Span w) 

leafSpan :: w -> Span wSource

Make span for a leaf node.

(<>) :: Ord w => Span w -> Span w -> Span wSource

Minimum span overlapping both input spans.

spanSet :: Ix w => Span w -> Set wSource

Set of positions covered by the span.

Trees with span

span :: Tree (a, Span w) -> Span wSource

Get span of the span-annotated tree.

spanTree :: Ord w => Tree (Either n w) -> Tree (Either n w, Span w)Source

Annotate tree nodes with spanning info given the function which assignes indices to leaf nodes.

spanForest :: Ord w => Forest (Either n w) -> Forest (Either n w, Span w)Source

Annotate forest nodes with spanning info.

unSpanTree :: Tree (k, Span w) -> Tree kSource

Remove span annotations from the tree.

unSpanForest :: Forest (k, Span w) -> Forest kSource

Remove span annotations from the forest.

sortTree :: Ord w => Tree (k, Span w) -> Tree (k, Span w)Source

Sort the tree with respect to spanning info.

sortForest :: Ord w => Forest (k, Span w) -> Forest (k, Span w)Source

Sort the forest with respect to spanning info.

Utilities

mapForest :: (a -> b) -> Forest a -> Forest bSource

Map function over each tree from the forest.

mapTree :: (a -> b) -> Tree a -> Tree bSource

Map function over the tree.

onLeaf :: (a -> b) -> Either c a -> Either c bSource

Map function over the leaf value.

onNode :: (a -> b) -> Either a c -> Either b cSource

Map function over the internal node value.

onEither :: (a -> c) -> (b -> d) -> Either a b -> Either c dSource

Map the first function over internal node value and the second one over leaf value.

onBoth :: (a -> b) -> Either a a -> Either b bSource

Map one function over both node and leaf values.

module Data.Tree