Copyright | (c) Adrian Hey 2004-2008 |
---|---|
License | BSD3 |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Data.COrdering
Description
This module defines a useful variant of the Prelude Ordering
data type.
Typically this data type is used as the result of a "combining comparison"
which combines values that are deemed to be equal (somehow). Note that the
functions defined here adhere to the same ordering convention as the overloaded
compare
(from the Ord
class):
a `compare` b -> LT (or Lt) implies a < b a `compare` b -> GT (or Gt) implies a > b
The combinators exported from this module have a CC
suffix if they
return a combining comparison (most of them) and a C
suffix if they return
an ordinary comparison. All the combinators defined here are INLINE
d, in the hope
that the compiler can avoid the overhead of using HOFs for frequently
used comparisons.
Synopsis
- data COrdering a
- unitCC :: Ord a => a -> a -> COrdering ()
- unitByCC :: (a -> b -> Ordering) -> a -> b -> COrdering ()
- fstCC :: Ord a => a -> a -> COrdering a
- fstByCC :: (a -> b -> Ordering) -> a -> b -> COrdering a
- sndCC :: Ord a => a -> a -> COrdering a
- sndByCC :: (a -> b -> Ordering) -> a -> b -> COrdering b
- flipC :: (a -> b -> Ordering) -> b -> a -> Ordering
- flipCC :: (a -> b -> COrdering c) -> b -> a -> COrdering c
- withCC :: Ord a => (a -> a -> b) -> a -> a -> COrdering b
- withCC' :: Ord a => (a -> a -> b) -> a -> a -> COrdering b
- withByCC :: (a -> b -> Ordering) -> (a -> b -> c) -> a -> b -> COrdering c
- withByCC' :: (a -> b -> Ordering) -> (a -> b -> c) -> a -> b -> COrdering c
Documentation
Result of a combining comparison.
Instances
Read a => Read (COrdering a) Source # | |
Show a => Show (COrdering a) Source # | |
Eq a => Eq (COrdering a) Source # | |
Ord a => Ord (COrdering a) Source # | |
Defined in Data.COrdering |
Useful combinators
unitCC :: Ord a => a -> a -> COrdering () Source #
A combining comparison for an instance of Ord
which returns unit ()
where appropriate.
unitByCC :: (a -> b -> Ordering) -> a -> b -> COrdering () Source #
Create a combining comparison from an ordinary comparison by returning unit ()
where appropriate.
fstCC :: Ord a => a -> a -> COrdering a Source #
A combining comparison for an instance of Ord
which keeps the first argument
if they are deemed equal. The second argument is discarded in this case.
fstByCC :: (a -> b -> Ordering) -> a -> b -> COrdering a Source #
Create a combining comparison from an ordinary comparison by keeping the first argument if they are deemed equal. The second argument is discarded in this case.
sndCC :: Ord a => a -> a -> COrdering a Source #
A combining comparison for an instance of Ord
which keeps the second argument
if they are deemed equal. The first argument is discarded in this case.
sndByCC :: (a -> b -> Ordering) -> a -> b -> COrdering b Source #
Create a combining comparison from an ordinary comparison by keeping the second argument if they are deemed equal. The first argument is discarded in this case.
flipC :: (a -> b -> Ordering) -> b -> a -> Ordering Source #
Converts a comparison to one which takes arguments in flipped order, but
preserves the ordering that would be given by the "unflipped" version (disregarding type issues).
So it's not the same as using the prelude flip
(which would reverse the ordering too).
flipCC :: (a -> b -> COrdering c) -> b -> a -> COrdering c Source #
Converts a combining comparison to one which takes arguments in flipped order, but
preserves the ordering that would be given by the "unflipped" version (disregarding type issues).
So it's not the same as using the prelude flip
(which would reverse the ordering too).
For combining "equal" values with a user supplied function
withCC' :: Ord a => (a -> a -> b) -> a -> a -> COrdering b Source #
Same as withCC
, except the combining function is applied strictly.