Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
- data Range a
- range :: Ord a => a -> a -> Range a
- sized :: Num a => Int -> a -> Range a
- empty :: Num a => a -> Range a
- begin :: Range a -> a
- end :: Range a -> a
- last :: Enum a => Range a -> a
- size :: Integral a => Range a -> Int
- null :: Eq a => Range a -> Bool
- toList :: Enum a => Range a -> [a]
- within :: Ord a => a -> Range a -> Bool
- adjoins :: Eq a => Range a -> Range a -> Bool
- overlaps :: Ord a => Range a -> Range a -> Bool
- contains :: Ord a => Range a -> Range a -> Bool
- split :: Integral a => Int -> Range a -> (Range a, Range a)
- join :: Ord a => Range a -> Range a -> Range a
Documentation
range :: Ord a => a -> a -> Range a Source
Construct a range from a lower bound (included) and an upper bound (excluded).
\(r :: Range Int) -> begin r == end r
sized :: Num a => Int -> a -> Range a Source
Construct a range from a size and a lower bound.
>>>
sized 20 10
Range 10 30
empty :: Num a => a -> Range a Source
The empty range starting at some value.
>>>
empty 10
Range 10 10
null (empty 10) True
size (empty 10) 0
size :: Integral a => Range a -> Int Source
The size of the range.
>>>
size (range 10 20)
10
>>>
size (sized 100 10)
100
null :: Eq a => Range a -> Bool Source
True if range is empty.
>>>
null (range 10 10)
True
>>>
null (range 10 20)
False
Interval operations
within :: Ord a => a -> Range a -> Bool Source
Return true if a given value is contained within the range.
>>>
within 12 (sized 3 10)
True
>>>
within 20 (range 10 20)
False
>>>
within 30 (range 30 30)
False
adjoins :: Eq a => Range a -> Range a -> Bool Source
Return true if two ranges adjoin each other.
>>>
range 10 20 `adjoins` range 20 30
True
>>>
range 10 20 `adjoins` range 21 30
False
contains :: Ord a => Range a -> Range a -> Bool Source
Return true if the second range lies completely within the first range.