GroteTrap-0.5.2: Parser and selection library for expression languages.

Language.GroteTrap.Range

Contents

Synopsis

# Types

type Pos = Int Source #

A Pos is a position in between two elements in a list. For example, position 0 marks the beginning of the list, and position length list marks the end of the list. There are n + 1 valid positions for a list of length n.

type Range = (Pos, Pos) Source #

A range's positions mark the begin and end of a sublist, respectively.

class Ranged a where Source #

Something that knows its range as sublist in a larger list. Minimal complete definition: either range or both begin and end.

Methods

range :: a -> Range Source #

Yields the element's range.

begin :: a -> Pos Source #

Yields the element's begin position.

end :: a -> Pos Source #

Yields the element's end position.

Instances

 Source # Methods

# Utility functions

distRange (b1, e1) (b2, e2) is defined as |b1 - b2| + |e1 - e2|.

Whether a position falls within a range, including the range's edges.

Yields whether the second argument completely falls within the first argument.

unionRange x y yields the smallest range z such that x includes z and y includes z.

A range's size is the number of elements it contains.

A range is valid if its positions are nonnegative and begin < end.