| Portability | portable |
|---|---|
| Stability | provisional |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Safe Haskell | Safe |
Data.Functor.Contravariant
Description
Contravariant functors, sometimes referred to colloquially as Cofunctor,
even though the dual of a Functor is just a Functor. As with Functor
the definition of Contravariant for a given ADT is unambiguous.
- class Contravariant f where
- contramap :: (a -> b) -> f b -> f a
- (>$<) :: Contravariant f => (a -> b) -> f b -> f a
- (>$$<) :: Contravariant f => f b -> (a -> b) -> f a
- newtype Predicate a = Predicate {
- getPredicate :: a -> Bool
- newtype Comparison a = Comparison {
- getComparison :: a -> a -> Ordering
- defaultComparison :: Ord a => Comparison a
- newtype Equivalence a = Equivalence {
- getEquivalence :: a -> a -> Bool
- defaultEquivalence :: Eq a => Equivalence a
- newtype Op a b = Op {
- getOp :: b -> a
Contravariant Functors
class Contravariant f whereSource
Any instance should be subject to the following laws:
contramap id = id contramap f . contramap g = contramap (g . f)
Note, that the second law follows from the free theorem of the type of
contramap and the first law, so you need only check that the former
condition holds.
Instances
| Contravariant Equivalence | Equivalence relations are |
| Contravariant Comparison | A |
| Contravariant Predicate | A |
| Contravariant (Const a) | |
| Contravariant (Proxy *) | |
| Contravariant f => Contravariant (Reverse f) | |
| Contravariant f => Contravariant (Backwards f) | |
| Contravariant (Constant a) | |
| Contravariant (Op a) | |
| (Functor f, Contravariant g) => Contravariant (Compose f g) | |
| (Contravariant f, Contravariant g) => Contravariant (Product f g) | |
| (Contravariant f, Functor g) => Contravariant (ComposeCF f g) | |
| (Functor f, Contravariant g) => Contravariant (ComposeFC f g) | |
| Contravariant (Day f g) |
Operators
(>$<) :: Contravariant f => (a -> b) -> f b -> f aSource
(>$$<) :: Contravariant f => f b -> (a -> b) -> f aSource
Predicates
Constructors
| Predicate | |
Fields
| |
Instances
| Typeable1 Predicate | |
| Contravariant Predicate | A |
Comparisons
newtype Comparison a Source
Defines a total ordering on a type as per compare
Constructors
| Comparison | |
Fields
| |
Instances
| Typeable1 Comparison | |
| Contravariant Comparison | A |
defaultComparison :: Ord a => Comparison aSource
Compare using compare
Equivalence Relations
newtype Equivalence a Source
Define an equivalence relation
Constructors
| Equivalence | |
Fields
| |
Instances
| Typeable1 Equivalence | |
| Contravariant Equivalence | Equivalence relations are |
defaultEquivalence :: Eq a => Equivalence aSource
Check for equivalence with ==