contravariant-0.1.0.1: Haskell 98 contravariant functors

Portability portable provisional Edward Kmett

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.

Synopsis

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.

Methods

contramap :: (a -> b) -> f b -> f aSource

Instances

 Contravariant Equivalence Equivalence relations are Contravariant, because you can apply the contramapped function to each input to the equivalence relation. Contravariant Comparison A Comparison is a Contravariant Functor, because contramap can apply its function argument to each input to each input to the comparison function. Contravariant Predicate A Predicate is a Contravariant Functor, because contramap can apply its function argument to the input of the predicate.

Predicates

newtype Predicate a Source

Constructors

 Predicate FieldsgetPredicate :: a -> Bool

Instances

 Contravariant Predicate A Predicate is a Contravariant Functor, because contramap can apply its function argument to the input of the predicate.

Comparisons

newtype Comparison a Source

Defines a total ordering on a type as per compare

Constructors

 Comparison FieldsgetComparison :: a -> a -> Ordering

Instances

 Contravariant Comparison A Comparison is a Contravariant Functor, because contramap can apply its function argument to each input to each input to the comparison function.

Compare using compare

Equivalence Relations

newtype Equivalence a Source

Define an equivalence relation

Constructors

 Equivalence FieldsgetEquivalence :: a -> a -> Bool

Instances

 Contravariant Equivalence Equivalence relations are Contravariant, because you can apply the contramapped function to each input to the equivalence relation.

Check for equivalence with ==