contravariant-1.2.0.1: Contravariant functors

Copyright(C) 2007-2014 Edward Kmett
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
Portabilityportable
Safe HaskellSafe
LanguageHaskell98

Data.Functor.Contravariant

Contents

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 where Source

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.

Minimal complete definition

contramap

Methods

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

(>$) :: b -> f b -> f a infixl 4 Source

Replace all locations in the output with the same value. The default definition is contramap . const, but this may be overridden with a more efficient version.

Instances

Contravariant V1 
Contravariant U1 
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.

Contravariant f => Contravariant (Rec1 f) 
Contravariant (Const a) 
Contravariant (Proxy *) 
Contravariant f => Contravariant (Reverse f) 
Contravariant f => Contravariant (Backwards f) 
Contravariant (Constant a) 
Contravariant (Op a) 
Contravariant (K1 i c) 
(Contravariant f, Contravariant g) => Contravariant ((:+:) f g) 
(Contravariant f, Contravariant g) => Contravariant ((:*:) f g) 
(Functor f, Contravariant g) => Contravariant ((:.:) f g) 
(Contravariant f, Contravariant g) => Contravariant (Sum f g) 
(Contravariant f, Contravariant g) => Contravariant (Product f g) 
(Functor f, Contravariant g) => Contravariant (Compose f g) 
(Contravariant f, Functor g) => Contravariant (ComposeCF f g) 
(Functor f, Contravariant g) => Contravariant (ComposeFC f g) 
Contravariant f => Contravariant (M1 i c f) 

Operators

(>$<) :: Contravariant f => (a -> b) -> f b -> f a infixl 4 Source

(>$$<) :: Contravariant f => f b -> (a -> b) -> f a infixl 4 Source

Predicates

newtype Predicate a Source

Constructors

Predicate 

Fields

getPredicate :: a -> Bool
 

Instances

Contravariant Predicate

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

Decidable Predicate 
Divisible Predicate 
Typeable (* -> *) Predicate 

Comparisons

newtype Comparison a Source

Defines a total ordering on a type as per compare

Constructors

Comparison 

Fields

getComparison :: 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.

Decidable Comparison 
Divisible Comparison 
Monoid (Comparison a) 
Semigroup (Comparison a) 
Typeable (* -> *) Comparison 

Equivalence Relations

newtype Equivalence a Source

Define an equivalence relation

Constructors

Equivalence 

Fields

getEquivalence :: a -> a -> Bool
 

Instances

Contravariant Equivalence

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

Decidable Equivalence 
Divisible Equivalence 
Monoid (Equivalence a) 
Semigroup (Equivalence a) 
Typeable (* -> *) Equivalence 

defaultEquivalence :: Eq a => Equivalence a Source

Check for equivalence with ==

Dual arrows

newtype Op a b Source

Dual function arrows.

Constructors

Op 

Fields

getOp :: b -> a
 

Instances

Category * Op 
Contravariant (Op a) 
Monoid r => Decidable (Op r) 
Monoid r => Divisible (Op r) 
Floating a => Floating (Op a b) 
Fractional a => Fractional (Op a b) 
Num a => Num (Op a b) 
Monoid a => Monoid (Op a b) 
Semigroup a => Semigroup (Op a b) 
Typeable (* -> * -> *) Op