Copyright | (c) Christoph Breitkopf 2014 |
---|---|

License | BSD-style |

Maintainer | chbreitkopf@gmail.com |

Stability | experimental |

Portability | non-portable (MPTC with FD) |

Safe Haskell | Safe |

Language | Haskell98 |

Type class for IntervalMap keys.

As there is no sensible default, no instances for prelude types are provided (E.g. you might want to have tuples as closed intervals in one case, and open in another).

Empty intervals, i.e. intervals where 'lowerBound >= upperBound' should be avoided
if possible. If you must use empty intervals, you need to provide implementations
for all operations, as the default implementations do not necessarily work correctly.
for example, the default implementation of `inside`

returns `True`

if the point
is equal to the lowerBound of a left-closed interval even if it is larger than
the upper bound.

- class Ord e => Interval i e | i -> e where
- genericEquals :: (Interval i e, Eq e) => i -> i -> Bool
- genericCompare :: (Interval i e, Ord e) => i -> i -> Ordering

# Interval type

class Ord e => Interval i e | i -> e where Source

Intervals with endpoints of type `e`

.
A minimal instance declaration for a closed interval needs only
to define `lowerBound`

and `upperBound`

.

lowerBound :: i -> e Source

lower bound

upperBound :: i -> e Source

upper bound

leftClosed :: i -> Bool Source

Does the interval include its lower bound? Default is True for all values, i.e. closed intervals.

rightClosed :: i -> Bool Source

Does the interval include its upper bound bound? Default is True for all values, i.e. closed intervals.

before :: i -> i -> Bool Source

Interval strictly before another? True if the upper bound of the first interval is below the lower bound of the second.

after :: i -> i -> Bool Source

Interval strictly after another? Same as 'flip before'.

subsumes :: i -> i -> Bool Source

Does the first interval completely contain the second?

overlaps :: i -> i -> Bool Source

Do the two intervals overlap?

below :: e -> i -> Bool Source

Is a point strictly less than lower bound?

above :: e -> i -> Bool Source

Is a point strictly greater than upper bound?

inside :: e -> i -> Bool Source

Does the interval contain a given point?

Is the interval empty?

# helper functions for declaring Eq and Ord instances

genericEquals :: (Interval i e, Eq e) => i -> i -> Bool Source

genericCompare :: (Interval i e, Ord e) => i -> i -> Ordering Source