class Contravariant (f :: Type -> Type) where Source #
The class of contravariant functors.
Whereas in Haskell, one can think of a Functor
as containing or producing values, a contravariant functor is a functor that can be thought of as consuming values.
As an example, consider the type of predicate functions a -> Bool
. One such predicate might be negative x = x < 0
, which classifies integers as to whether they are negative. However, given this predicate, we can re-use it in other situations, providing we have a way to map values to integers. For instance, we can use the negative
predicate on a person's bank balance to work out if they are currently overdrawn:
newtype Predicate a = Predicate { getPredicate :: a -> Bool } instance Contravariant Predicate where contramap :: (a' -> a) -> (Predicate a -> Predicate a') contramap f (Predicate p) = Predicate (p . f) | `- First, map the input... `----- then apply the predicate. overdrawn :: Predicate Person overdrawn = contramap personBankBalance negative
Any instance should be subject to the following laws:
contramap
id
= id
contramap
(g . f) = contramap
f . contramap
g
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' -> a) -> f a -> 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
, but this may be overridden with a more efficient version.contramap
. const
newtype Comparison a Source #
Defines a total ordering on a type as per compare
.
This condition is not checked by the types. You must ensure that the supplied values are valid total orderings yourself.
Instances Instances details Equivalence RelationscomparisonEquivalence :: Comparison a -> Equivalence a Source #
Dual arrowsDual function arrows.
Instances Instances detailsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4