Copyright | (c) Christoph Breitkopf 2011 |
---|---|
License | BSD-style |
Maintainer | chbreitkopf@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell98 |
A conservative implementation of Intervals, mostly for use as keys in
a IntervalMap
.
This should really be a typeclass, so you could have a tuple be an instance of Interval, but that is currently not possible in standard Haskell.
The contructor names of the half-open intervals seem somewhat clumsy, and I'm open to suggestions for better names.
Synopsis
- data Interval a
- = IntervalCO !a !a
- | ClosedInterval !a !a
- | OpenInterval !a !a
- | IntervalOC !a !a
- lowerBound :: Interval a -> a
- upperBound :: Interval a -> a
- leftClosed :: Interval a -> Bool
- rightClosed :: Interval a -> Bool
- isEmpty :: Ord a => Interval a -> Bool
- overlaps :: Ord a => Interval a -> Interval a -> Bool
- subsumes :: Ord a => Interval a -> Interval a -> Bool
- before :: Ord a => Interval a -> Interval a -> Bool
- after :: Ord a => Interval a -> Interval a -> Bool
- compareByUpper :: Ord a => Interval a -> Interval a -> Ordering
- combine :: Ord a => Interval a -> Interval a -> Maybe (Interval a)
- below :: Ord a => a -> Interval a -> Bool
- inside :: Ord a => a -> Interval a -> Bool
- above :: Ord a => a -> Interval a -> Bool
Interval type
Intervals with endpoints of type a
.
Read
and Show
use mathematical notation with square brackets for closed
and parens for open intervals.
This is better for human readability, but is not a valid Haskell expression.
Closed intervals look like a list, open intervals look like a tuple,
and half-open intervals look like mismatched parens.
IntervalCO !a !a | Including lower bound, excluding upper |
ClosedInterval !a !a | Closed at both ends |
OpenInterval !a !a | Open at both ends |
IntervalOC !a !a | Excluding lower bound, including upper |
Instances
Functor Interval Source # | |
Eq a => Eq (Interval a) Source # | |
Ord a => Ord (Interval a) Source # | |
Read a => Read (Interval a) Source # | |
Show a => Show (Interval a) Source # | |
NFData a => NFData (Interval a) Source # | |
Defined in Data.IntervalMap.Interval | |
Ord a => Interval (Interval a) a Source # | |
Defined in Data.IntervalMap.Generic.Interval lowerBound :: Interval a -> a Source # upperBound :: Interval a -> a Source # leftClosed :: Interval a -> Bool Source # rightClosed :: Interval a -> Bool Source # before :: Interval a -> Interval a -> Bool Source # after :: Interval a -> Interval a -> Bool Source # subsumes :: Interval a -> Interval a -> Bool Source # overlaps :: Interval a -> Interval a -> Bool Source # below :: a -> Interval a -> Bool Source # above :: a -> Interval a -> Bool Source # inside :: a -> Interval a -> Bool Source # isEmpty :: Interval a -> Bool Source # compareUpperBounds :: Interval a -> Interval a -> Ordering Source # |
Query
lowerBound :: Interval a -> a Source #
Get the lower bound.
upperBound :: Interval a -> a Source #
Get the upper bound.
leftClosed :: Interval a -> Bool Source #
Does the interval include its lower bound?
rightClosed :: Interval a -> Bool Source #
Does the interval include its upper bound?
Interval operations
subsumes :: Ord a => Interval a -> Interval a -> Bool Source #
Does the first interval completely contain the second?
before :: Ord a => Interval a -> Interval a -> Bool Source #
Interval strictly before another? True if the upper bound of the first interval is below the lower bound of the second.
after :: Ord a => Interval a -> Interval a -> Bool Source #
Interval strictly after another? Same as 'flip before'.
compareByUpper :: Ord a => Interval a -> Interval a -> Ordering Source #
Like compare
, but considering the upper bound first.
combine :: Ord a => Interval a -> Interval a -> Maybe (Interval a) Source #
If the intervals overlap combine them into one.