This is >$ with its arguments flipped.
Modulebase-compat-batteries-0.14.1Haskell2010
Data.Functor.Contravariant.Compat
- 4 types
- 1 class
- 7 values
- Packagebase-compat-batteries-0.14.1
- Exports12
- LanguageHaskell2010
- LicenceMIT
- SourceContravariant.hs
This is an infix version of contramap with the arguments flipped.
This is an infix alias for contramap.
Compare using compare.
If f is both Functor and Contravariant 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 ≡ phantom
contramap f ≡ phantom
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.
Constructors
ComparisongetComparison :: a -> a -> Ordering
Instances3Contravariant, Semigroup, Monoid
Contravariant ComparisonDefined in base-4.20.2.0 · Data.Functor.ContravariantA Comparison is a Contravariant Functor, because contramap can apply its function argument to each input of the comparison function.
Semigroup (Comparison a)Defined in base-4.20.2.0 · Data.Functor.ContravariantMonoid (Comparison a)Defined in base-4.20.2.0 · Data.Functor.Contravariant
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:
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.
Instances31Contravariant, …
Contravariant ComparisonDefined in base-4.20.2.0 · Data.Functor.ContravariantA Comparison is a Contravariant Functor, because contramap can apply its function argument to each input of the comparison function.
Contravariant EquivalenceDefined in base-4.20.2.0 · Data.Functor.ContravariantEquivalence relations are Contravariant, because you can apply the contramapped function to each input to the equivalence relation.
Contravariant PredicateDefined in base-4.20.2.0 · Data.Functor.ContravariantA Predicate is a Contravariant Functor, because contramap can apply its function argument to the input of the predicate.
Without newtypes
contramap fequals precomposing withf(=(. f)).contramap :: (a' -> a) -> (Predicate a -> Predicate a') contramap f (Predicate g) = Predicate (g . f)Contravariant ProxyDefined in base-4.20.2.0 · Data.Functor.ContravariantContravariant U1Defined in base-4.20.2.0 · Data.Functor.ContravariantContravariant V1Defined in base-4.20.2.0 · Data.Functor.ContravariantContravariant (Op a)Defined in base-4.20.2.0 · Data.Functor.ContravariantContravariant m => Contravariant (MaybeT m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.MaybeContravariant (Const a)Defined in base-4.20.2.0 · Data.Functor.ContravariantContravariant (Constant a)Defined in transformers-0.6.1.1 · Data.Functor.ConstantContravariant f => Contravariant (Alt f)Defined in base-4.20.2.0 · Data.Functor.ContravariantContravariant f => Contravariant (Rec1 f)Defined in base-4.20.2.0 · Data.Functor.ContravariantContravariant f => Contravariant (Backwards f)Defined in transformers-0.6.1.1 · Control.Applicative.BackwardsDerived instance.
Contravariant f => Contravariant (IdentityT f)Defined in transformers-0.6.1.1 · Control.Monad.Trans.IdentityContravariant f => Contravariant (Reverse f)Defined in transformers-0.6.1.1 · Data.Functor.ReverseDerived instance.
Contravariant m => Contravariant (ExceptT e m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ExceptContravariant m => Contravariant (ReaderT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ReaderContravariant m => Contravariant (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.LazyContravariant m => Contravariant (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.StrictContravariant m => Contravariant (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.LazyContravariant m => Contravariant (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.StrictContravariant (K1 i c)Defined in base-4.20.2.0 · Data.Functor.Contravariant(Contravariant f, Contravariant g) => Contravariant (Product f g)Defined in base-4.20.2.0 · Data.Functor.Contravariant(Contravariant f, Contravariant g) => Contravariant (Sum f g)Defined in base-4.20.2.0 · Data.Functor.Contravariant(Contravariant f, Contravariant g) => Contravariant (f :*: g)Defined in base-4.20.2.0 · Data.Functor.Contravariant(Contravariant f, Contravariant g) => Contravariant (f :+: g)Defined in base-4.20.2.0 · Data.Functor.ContravariantContravariant f => Contravariant (M1 i c f)Defined in base-4.20.2.0 · Data.Functor.ContravariantContravariant m => Contravariant (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.LazyContravariant m => Contravariant (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.Strict(Functor f, Contravariant g) => Contravariant (Compose f g)Defined in base-4.20.2.0 · Data.Functor.Contravariant(Functor f, Contravariant g) => Contravariant (f :.: g)Defined in base-4.20.2.0 · Data.Functor.Contravariant
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
If
getEquivalence f a band
getEquivalence f b care both
then so is
getEquivalence f a c.
The types alone do not enforce these laws, so you'll have to check them yourself.
Constructors
EquivalencegetEquivalence :: a -> a -> Bool
Instances3Contravariant, Semigroup, Monoid
Contravariant EquivalenceDefined in base-4.20.2.0 · Data.Functor.ContravariantEquivalence relations are Contravariant, because you can apply the contramapped function to each input to the equivalence relation.
Semigroup (Equivalence a)Defined in base-4.20.2.0 · Data.Functor.ContravariantMonoid (Equivalence a)Defined in base-4.20.2.0 · Data.Functor.Contravariant
Instances7Category, Contravariant, Floating, Fractional, Num, Semigroup, …
Category OpDefined in base-4.20.2.0 · Data.Functor.ContravariantContravariant (Op a)Defined in base-4.20.2.0 · Data.Functor.ContravariantFloating a => Floating (Op a b)Defined in base-4.20.2.0 · Data.Functor.ContravariantFractional a => Fractional (Op a b)Defined in base-4.20.2.0 · Data.Functor.ContravariantNum a => Num (Op a b)Defined in base-4.20.2.0 · Data.Functor.ContravariantSemigroup a => Semigroup (Op a b)Defined in base-4.20.2.0 · Data.Functor.ContravariantMonoid a => Monoid (Op a b)Defined in base-4.20.2.0 · Data.Functor.Contravariantmempty @(Op a b)without newtypes ismempty @(b->a)=_ -> mempty.mempty :: Op a b mempty = Op _ -> mempty
Constructors
PredicategetPredicate :: a -> Bool
Instances3Contravariant, Semigroup, Monoid
Contravariant PredicateDefined in base-4.20.2.0 · Data.Functor.ContravariantA Predicate is a Contravariant Functor, because contramap can apply its function argument to the input of the predicate.
Without newtypes
contramap fequals precomposing withf(=(. f)).contramap :: (a' -> a) -> (Predicate a -> Predicate a') contramap f (Predicate g) = Predicate (g . f)Semigroup (Predicate a)Defined in base-4.20.2.0 · Data.Functor.ContravariantMonoid (Predicate a)Defined in base-4.20.2.0 · Data.Functor.Contravariant