coda-0.0.1: The coda compiler

Copyright(c) Edward Kmett 2017 (c) Ross Paterson Ralf Hinze 2006
LicenseBSD-style
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Coda.FingerTree

Contents

Description

 

Synopsis

Documentation

data FingerTree a Source #

A representation of a sequence of values of type a, allowing access to the ends in constant time, and append and split in time logarithmic in the size of the smaller piece.

A variety of abstract data types can be implemented by using different element types and measurements.

Constructors

EmptyTree 
Singleton a 

Instances

Foldable FingerTree Source #

Elements from left to right.

Methods

fold :: Monoid m => FingerTree m -> m #

foldMap :: Monoid m => (a -> m) -> FingerTree a -> m #

foldr :: (a -> b -> b) -> b -> FingerTree a -> b #

foldr' :: (a -> b -> b) -> b -> FingerTree a -> b #

foldl :: (b -> a -> b) -> b -> FingerTree a -> b #

foldl' :: (b -> a -> b) -> b -> FingerTree a -> b #

foldr1 :: (a -> a -> a) -> FingerTree a -> a #

foldl1 :: (a -> a -> a) -> FingerTree a -> a #

toList :: FingerTree a -> [a] #

null :: FingerTree a -> Bool #

length :: FingerTree a -> Int #

elem :: Eq a => a -> FingerTree a -> Bool #

maximum :: Ord a => FingerTree a -> a #

minimum :: Ord a => FingerTree a -> a #

sum :: Num a => FingerTree a -> a #

product :: Num a => FingerTree a -> a #

Measured a => IsList (FingerTree a) Source # 

Associated Types

type Item (FingerTree a) :: * #

Eq a => Eq (FingerTree a) Source # 

Methods

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

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

Ord a => Ord (FingerTree a) Source # 
Show a => Show (FingerTree a) Source # 
Measured a => Semigroup (FingerTree a) Source #

O(log(min(n1,n2))). Concatenate two sequences.

Measured a => Monoid (FingerTree a) Source # 
AsEmpty (FingerTree a) Source # 

Methods

_Empty :: Prism' (FingerTree a) ()

Default (FingerTree a) Source # 

Methods

def :: FingerTree a

Measured a => Measured (FingerTree a) Source #

O(1). The cached measure of a tree.

Associated Types

type Measure (FingerTree a) :: * Source #

(Measured a, HasMonoidalDelta (Measure a)) => HasMonoidalDelta (FingerTree a) Source # 
(Measured a, HasDelta (Measure a)) => HasDelta (FingerTree a) Source # 

Methods

delta :: FingerTree a -> Delta Source #

Strippable (FingerTree Text) Source # 
Splittable a => Splittable (FingerTree a) Source # 
(Measured a, Measured b) => Snoc (FingerTree a) (FingerTree b) a b Source # 

Methods

_Snoc :: Prism (FingerTree a) (FingerTree b) (FingerTree a, a) (FingerTree b, b)

(Measured a, Measured b) => Cons (FingerTree a) (FingerTree b) a b Source # 

Methods

_Cons :: Prism (FingerTree a) (FingerTree b) (a, FingerTree a) (b, FingerTree b)

type Item (FingerTree a) Source # 
type Item (FingerTree a) = a
type Measure (FingerTree a) Source # 

class Monoid (Measure a) => Measured a where Source #

Things that can be measured.

Minimal complete definition

measure

Associated Types

type Measure a :: * Source #

Methods

measure :: a -> Measure a Source #

Instances

Measured Text Source # 

Associated Types

type Measure Text :: * Source #

Measured Delta Source # 

Associated Types

type Measure Delta :: * Source #

Measured Change Source # 

Associated Types

type Measure Change :: * Source #

Measured Edit Source # 

Associated Types

type Measure Edit :: * Source #

Measured Rope Source # 

Associated Types

type Measure Rope :: * Source #

Measured Line Source # 

Associated Types

type Measure Line :: * Source #

Measured Document Source # 

Associated Types

type Measure Document :: * Source #

Measured a => Measured (FingerTree a) Source #

O(1). The cached measure of a tree.

Associated Types

type Measure (FingerTree a) :: * Source #

Construction

empty :: FingerTree a Source #

O(1). The empty sequence.

singleton :: a -> FingerTree a Source #

O(1). A singleton sequence.

fromList :: IsList l => [Item l] -> l #

The fromList function constructs the structure l from the given list of Item l

Deconstruction

Search

data SearchResult a Source #

A result of search, attempting to find a point where a predicate on splits of the sequence changes from False to True.

Constructors

Position (FingerTree a) a (FingerTree a)

A tree opened at a particular element: the prefix to the left, the element, and the suffix to the right.

OnLeft

A position to the left of the sequence, indicating that the predicate is True at both ends.

OnRight

A position to the right of the sequence, indicating that the predicate is False at both ends.

Nowhere

No position in the tree, returned if the predicate is True at the left end and False at the right end. This will not occur if the predicate in monotonic on the tree.

search :: Measured a => (Measure a -> Measure a -> Bool) -> FingerTree a -> SearchResult a Source #

O(log(min(i,n-i))). Search a sequence for a point where a predicate on splits of the sequence changes from False to True.

The argument p is a relation between the measures of the two sequences that could be appended together to form the sequence t. If the relation is False at the leftmost split and True at the rightmost split, i.e.

not (p mempty (measure t)) && p (measure t) mempty

then there must exist an element x in the sequence such that p is False for the split immediately before x and True for the split just after it:

In this situation, search p t returns such an element x and the pieces l and r of the sequence to its left and right respectively. That is, it returns Position l x r such that

  • l >< (x <| r) = t
  • not (p (measure l) (measure (x <| r))
  • p (measure (l |> x)) (measure r)

For predictable results, one should ensure that there is only one such point, i.e. that the predicate is monotonic on t.

Splitting

These functions are special cases of search.

split :: Measured a => (Measure a -> Bool) -> FingerTree a -> (FingerTree a, FingerTree a) Source #

O(log(min(i,n-i))). Split a sequence at a point where the predicate on the accumulated measure of the prefix changes from False to True.

For predictable results, one should ensure that there is only one such point, i.e. that the predicate is monotonic.

takeUntil :: Measured a => (Measure a -> Bool) -> FingerTree a -> FingerTree a Source #

O(log(min(i,n-i))). Given a monotonic predicate p, takeUntil p t is the largest prefix of t whose measure does not satisfy p.

dropUntil :: Measured a => (Measure a -> Bool) -> FingerTree a -> FingerTree a Source #

O(log(min(i,n-i))). Given a monotonic predicate p, dropUntil p t is the rest of t after removing the largest prefix whose measure does not satisfy p.

Transformation

reverse :: Measured a => FingerTree a -> FingerTree a Source #

O(n). The reverse of a sequence.

Maps

fmap' :: Measured b => (a -> b) -> FingerTree a -> FingerTree b Source #

Like fmap, but with constraints on the element types.

fmapWithPos :: (Measured a, Measured b) => (Measure a -> a -> b) -> FingerTree a -> FingerTree b Source #

Map all elements of the tree with a function that also takes the measure of the prefix of the tree to the left of the element.

fmapWithContext :: (Measured a, Measured b) => (Measure a -> a -> Measure a -> b) -> FingerTree a -> FingerTree b Source #

Map all elements of the tree with a function that also takes the measure of the prefix to the left and of the suffix to the right of the element.

unsafeFmap :: Measure a ~ Measure b => (a -> b) -> FingerTree a -> FingerTree b Source #

Like fmap, but safe only if the function preserves the measure.

Traversals

traverse' :: (Measured b, Applicative f) => (a -> f b) -> FingerTree a -> f (FingerTree b) Source #

Like traverse, but with constraints on the element types.

traverseWithPos :: (Measured a, Measured b, Applicative f) => (Measure a -> a -> f b) -> FingerTree a -> f (FingerTree b) Source #

Traverse the tree from left to right with a function that also takes the measure of the prefix of the tree to the left of the element.

traverseWithContext :: (Measured a, Measured b, Applicative f) => (Measure a -> a -> Measure a -> f b) -> FingerTree a -> f (FingerTree b) Source #

Traverse the tree from left to right with a function that also takes the measure of the prefix to the left and the measure of the suffix to the right of the element.

unsafeTraverse :: (Measure a ~ Measure b, Applicative f) => (a -> f b) -> FingerTree a -> f (FingerTree b) Source #

Like traverse, but safe only if the function preserves the measure.