Movatterモバイル変換


[0]ホーム

URL:


base-4.12.0.0: Basic libraries

Copyright(C) 2007-2015 Edward Kmett
LicenseBSD-style (see the file LICENSE)
Maintainerlibraries@haskell.org
Stabilityprovisional
Portabilityportable
Safe HaskellTrustworthy
LanguageHaskell2010

Data.Functor.Contravariant

Contents

Description

Contravariant functors, sometimes referred to colloquially asCofunctor, even though the dual of aFunctor is just aFunctor. As withFunctor the definition ofContravariant for a given ADT is unambiguous.

Since: 4.12.0.0

Synopsis

Contravariant Functors

classContravariant fwhereSource#

The class of contravariant functors.

Whereas in Haskell, one can think of aFunctor as containing or producing values, a contravariant functor is a functor that can be thought of asconsuming values.

As an example, consider the type of predicate functionsa -> Bool. One such predicate might benegative 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 valuesto integers. For instance, we can use thenegative 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 f (Predicate p) = Predicate (p . f)                                         |   `- First, map the input...                                         `----- then apply the predicate.overdrawn :: Predicate Personoverdrawn = contramap personBankBalance negative

Any instance should be subject to the following laws:

contramap id = idcontramap f . contramap g = contramap (g . f)

Note, that the second law follows from the free theorem of the type ofcontramap 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 aSource#

(>$) :: b -> f b -> f ainfixl 4Source#

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

Instances
ContravariantEquivalenceSource#

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

Instance details

Defined inData.Functor.Contravariant

ContravariantComparisonSource#

AComparison is aContravariantFunctor, becausecontramap can apply its function argument to each input of the comparison function.

Instance details

Defined inData.Functor.Contravariant

ContravariantPredicateSource#

APredicate is aContravariantFunctor, becausecontramap can apply its function argument to the input of the predicate.

Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) ->Predicate b ->Predicate aSource#

(>$) :: b ->Predicate b ->Predicate aSource#

Contravariant (V1 ::Type ->Type)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) ->V1 b ->V1 aSource#

(>$) :: b ->V1 b ->V1 aSource#

Contravariant (U1 ::Type ->Type)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) ->U1 b ->U1 aSource#

(>$) :: b ->U1 b ->U1 aSource#

Contravariant (Proxy ::Type ->Type)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) ->Proxy b ->Proxy aSource#

(>$) :: b ->Proxy b ->Proxy aSource#

Contravariant (Op a)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a0 -> b) ->Op a b ->Op a a0Source#

(>$) :: b ->Op a b ->Op a a0Source#

Contravariant f =>Contravariant (Rec1 f)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

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

(>$) :: b ->Rec1 f b ->Rec1 f aSource#

Contravariant f =>Contravariant (Alt f)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

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

(>$) :: b ->Alt f b ->Alt f aSource#

Contravariant (Const a ::Type ->Type)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a0 -> b) ->Const a b ->Const a a0Source#

(>$) :: b ->Const a b ->Const a a0Source#

Contravariant (K1 i c ::Type ->Type)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) ->K1 i c b ->K1 i c aSource#

(>$) :: b ->K1 i c b ->K1 i c aSource#

(Contravariant f,Contravariant g) =>Contravariant (f:+: g)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) -> (f:+: g) b -> (f:+: g) aSource#

(>$) :: b -> (f:+: g) b -> (f:+: g) aSource#

(Contravariant f,Contravariant g) =>Contravariant (f:*: g)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) -> (f:*: g) b -> (f:*: g) aSource#

(>$) :: b -> (f:*: g) b -> (f:*: g) aSource#

(Contravariant f,Contravariant g) =>Contravariant (Sum f g)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) ->Sum f g b ->Sum f g aSource#

(>$) :: b ->Sum f g b ->Sum f g aSource#

(Contravariant f,Contravariant g) =>Contravariant (Product f g)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) ->Product f g b ->Product f g aSource#

(>$) :: b ->Product f g b ->Product f g aSource#

Contravariant f =>Contravariant (M1 i c f)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) ->M1 i c f b ->M1 i c f aSource#

(>$) :: b ->M1 i c f b ->M1 i c f aSource#

(Functor f,Contravariant g) =>Contravariant (f:.: g)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) -> (f:.: g) b -> (f:.: g) aSource#

(>$) :: b -> (f:.: g) b -> (f:.: g) aSource#

(Functor f,Contravariant g) =>Contravariant (Compose f g)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) ->Compose f g b ->Compose f g aSource#

(>$) :: b ->Compose f g b ->Compose f g aSource#

phantom :: (Functor f,Contravariant f) => f a -> f bSource#

Iff is bothFunctor andContravariant then by the time you factor in the laws of each of those classes, it can't actually use its argument in any meaningful capacity.

This method is surprisingly useful. Where both instances exist and are lawful we have the following laws:

fmap f ≡phantomcontramap f ≡phantom

Operators

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

This is an infix alias forcontramap.

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

This is an infix version ofcontramap with the arguments flipped.

($<) ::Contravariant f => f b -> b -> f ainfixl 4Source#

This is>$ with its arguments flipped.

Predicates

newtypePredicate aSource#

Constructors

Predicate 

Fields

Instances
ContravariantPredicateSource#

APredicate is aContravariantFunctor, becausecontramap can apply its function argument to the input of the predicate.

Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a -> b) ->Predicate b ->Predicate aSource#

(>$) :: b ->Predicate b ->Predicate aSource#

Semigroup (Predicate a)Source# 
Instance details

Defined inData.Functor.Contravariant

Monoid (Predicate a)Source# 
Instance details

Defined inData.Functor.Contravariant

Comparisons

newtypeComparison aSource#

Defines a total ordering on a type as percompare.

This condition is not checked by the types. You must ensure that the supplied values are valid total orderings yourself.

Constructors

Comparison 

Fields

Instances
ContravariantComparisonSource#

AComparison is aContravariantFunctor, becausecontramap can apply its function argument to each input of the comparison function.

Instance details

Defined inData.Functor.Contravariant

Semigroup (Comparison a)Source# 
Instance details

Defined inData.Functor.Contravariant

Monoid (Comparison a)Source# 
Instance details

Defined inData.Functor.Contravariant

defaultComparison ::Ord a =>Comparison aSource#

Compare usingcompare.

Equivalence Relations

newtypeEquivalence aSource#

This data type represents an equivalence relation.

Equivalence relations are expected to satisfy three laws:

Reflexivity:

getEquivalence f a a = True

Symmetry:

getEquivalence f a b =getEquivalence f b a

Transitivity:

IfgetEquivalence f a b andgetEquivalence f b c are bothTrue then so isgetEquivalence f a c.

The types alone do not enforce these laws, so you'll have to check them yourself.

Constructors

Equivalence 

Fields

Instances
ContravariantEquivalenceSource#

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

Instance details

Defined inData.Functor.Contravariant

Semigroup (Equivalence a)Source# 
Instance details

Defined inData.Functor.Contravariant

Monoid (Equivalence a)Source# 
Instance details

Defined inData.Functor.Contravariant

defaultEquivalence ::Eq a =>Equivalence aSource#

Check for equivalence with==.

Note: The instances forDouble andFloat violate reflexivity forNaN.

comparisonEquivalence ::Comparison a ->Equivalence aSource#

Dual arrows

newtypeOp a bSource#

Dual function arrows.

Constructors

Op 

Fields

Instances
Contravariant (Op a)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

contramap :: (a0 -> b) ->Op a b ->Op a a0Source#

(>$) :: b ->Op a b ->Op a a0Source#

CategoryOpSource# 
Instance details

Defined inData.Functor.Contravariant

Methods

id ::Op a aSource#

(.) ::Op b c ->Op a b ->Op a cSource#

Floating a =>Floating (Op a b)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

pi ::Op a bSource#

exp ::Op a b ->Op a bSource#

log ::Op a b ->Op a bSource#

sqrt ::Op a b ->Op a bSource#

(**) ::Op a b ->Op a b ->Op a bSource#

logBase ::Op a b ->Op a b ->Op a bSource#

sin ::Op a b ->Op a bSource#

cos ::Op a b ->Op a bSource#

tan ::Op a b ->Op a bSource#

asin ::Op a b ->Op a bSource#

acos ::Op a b ->Op a bSource#

atan ::Op a b ->Op a bSource#

sinh ::Op a b ->Op a bSource#

cosh ::Op a b ->Op a bSource#

tanh ::Op a b ->Op a bSource#

asinh ::Op a b ->Op a bSource#

acosh ::Op a b ->Op a bSource#

atanh ::Op a b ->Op a bSource#

log1p ::Op a b ->Op a bSource#

expm1 ::Op a b ->Op a bSource#

log1pexp ::Op a b ->Op a bSource#

log1mexp ::Op a b ->Op a bSource#

Fractional a =>Fractional (Op a b)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

(/) ::Op a b ->Op a b ->Op a bSource#

recip ::Op a b ->Op a bSource#

fromRational ::Rational ->Op a bSource#

Num a =>Num (Op a b)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

(+) ::Op a b ->Op a b ->Op a bSource#

(-) ::Op a b ->Op a b ->Op a bSource#

(*) ::Op a b ->Op a b ->Op a bSource#

negate ::Op a b ->Op a bSource#

abs ::Op a b ->Op a bSource#

signum ::Op a b ->Op a bSource#

fromInteger ::Integer ->Op a bSource#

Semigroup a =>Semigroup (Op a b)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

(<>) ::Op a b ->Op a b ->Op a bSource#

sconcat ::NonEmpty (Op a b) ->Op a bSource#

stimes ::Integral b0 => b0 ->Op a b ->Op a bSource#

Monoid a =>Monoid (Op a b)Source# 
Instance details

Defined inData.Functor.Contravariant

Methods

mempty ::Op a bSource#

mappend ::Op a b ->Op a b ->Op a bSource#

mconcat :: [Op a b] ->Op a bSource#

Produced byHaddock version 2.20.0


[8]ページ先頭

©2009-2025 Movatter.jp