Safe Haskell | Safe-Inferred |
---|

This entire library is concerned with ranges and this module implements the absolute basic range functions.

- data Range a
- = SingletonRange a
- | SpanRange a a
- | LowerBoundRange a
- | UpperBoundRange a
- | InfiniteRange

- inRange :: Ord a => Range a -> a -> Bool
- inRanges :: Ord a => [Range a] -> a -> Bool
- rangesOverlap :: Ord a => Range a -> Range a -> Bool
- mergeRanges :: (Ord a, Enum a) => [Range a] -> [Range a]
- invert :: (Ord a, Enum a) => [Range a] -> [Range a]
- union :: (Ord a, Enum a) => [Range a] -> [Range a] -> [Range a]
- intersection :: (Ord a, Enum a) => [Range a] -> [Range a] -> [Range a]
- fromRanges :: (Ord a, Enum a) => [Range a] -> [a]

# Documentation

The Range Data structure; it is capable of representing any type of range. This is the primary data structure in this library. Everything should be possible to convert back into this datatype. All ranges in this structure are inclusively bound.

SingletonRange a | Represents a single element as a range. |

SpanRange a a | Represents a bounded and inclusive range of elements. |

LowerBoundRange a | Represents a range with only an inclusive lower bound. |

UpperBoundRange a | Represents a range with only an inclusive upper bound. |

InfiniteRange | Represents an infinite range over all values. |

inRange :: Ord a => Range a -> a -> BoolSource

Given a range and a value it will tell you wether or not the value is in the range. Remember that all ranges are inclusive.

inRanges :: Ord a => [Range a] -> a -> BoolSource

Given a list of ranges this function tells you if a value is in any of those ranges. This is especially useful for more complex ranges.

rangesOverlap :: Ord a => Range a -> Range a -> BoolSource

A check to see if two ranges overlap. If they do then true is returned; false otherwise.

mergeRanges :: (Ord a, Enum a) => [Range a] -> [Range a]Source

When you create a range there may be overlaps in your ranges. However, for the sake of efficiency you probably want the list of ranges with no overlaps. The mergeRanges function takes a set of ranges and returns the same set specified by the minimum number of Range objects. A useful function for cleaning up your ranges. Please note that, if you use any of the other operations on sets of ranges like invert, union and intersection then this is automatically done for you. Which means that a function like this is redundant: mergeRanges . intersection

invert :: (Ord a, Enum a) => [Range a] -> [Range a]Source

An inversion function, given a set of ranges it returns the inverse set of ranges.

union :: (Ord a, Enum a) => [Range a] -> [Range a] -> [Range a]Source

Performs a set union between the two input ranges and returns the resultant set of ranges.

intersection :: (Ord a, Enum a) => [Range a] -> [Range a] -> [Range a]Source

Performs a set intersection between the two input ranges and returns the resultant set of ranges.

fromRanges :: (Ord a, Enum a) => [Range a] -> [a]Source

A set of ranges represents a collection of real values without actually instantiating those values. This allows you to have infinite ranges. However, sometimes you wish to actually get the values that your range represents, or even get a sample set of the values. This function generates as many of the values that belong to your range as you like.