contravariant-1.4: Contravariant functors

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

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 #

(>$) :: b -> f b -> f a infixl 4 # 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  # Methodscontramap :: (a -> b) -> V1 b -> V1 a #(>$) :: b -> V1 b -> V1 a # # Methodscontramap :: (a -> b) -> U1 b -> U1 a #(>$) :: b -> U1 b -> U1 a # # Methodscontramap :: (a -> b) -> SettableStateVar b -> SettableStateVar a #(>$) :: b -> SettableStateVar b -> SettableStateVar a # # Equivalence relations are Contravariant, because you can apply the contramapped function to each input to the equivalence relation. Methodscontramap :: (a -> b) -> Equivalence b -> Equivalence a #(>$) :: b -> Equivalence b -> Equivalence a # # A Comparison is a Contravariant Functor, because contramap can apply its function argument to each input of the comparison function. Methodscontramap :: (a -> b) -> Comparison b -> Comparison a #(>$) :: b -> Comparison b -> Comparison a # # A Predicate is a Contravariant Functor, because contramap can apply its function argument to the input of the predicate. Methodscontramap :: (a -> b) -> Predicate b -> Predicate a #(>$) :: b -> Predicate b -> Predicate a # # Methodscontramap :: (a -> b) -> Rec1 f b -> Rec1 f a #(>$) :: b -> Rec1 f b -> Rec1 f a # # Methodscontramap :: (a -> b) -> Proxy * b -> Proxy * a #(>$) :: b -> Proxy * b -> Proxy * a # # Methodscontramap :: (a -> b) -> MaybeT m b -> MaybeT m a #(>$) :: b -> MaybeT m b -> MaybeT m a # # Methodscontramap :: (a -> b) -> ListT m b -> ListT m a #(>$) :: b -> ListT m b -> ListT m a # # Methodscontramap :: (a -> b) -> Op a b -> Op a a #(>$) :: b -> Op a b -> Op a a # Contravariant (K1 i c) # Methodscontramap :: (a -> b) -> K1 i c b -> K1 i c a #(>$) :: b -> K1 i c b -> K1 i c a # (Contravariant f, Contravariant g) => Contravariant ((:+:) f g) # Methodscontramap :: (a -> b) -> (f :+: g) b -> (f :+: g) a #(>$) :: b -> (f :+: g) b -> (f :+: g) a # (Contravariant f, Contravariant g) => Contravariant ((:*:) f g) # Methodscontramap :: (a -> b) -> (f :*: g) b -> (f :*: g) a #(>$) :: b -> (f :*: g) b -> (f :*: g) a # (Functor f, Contravariant g) => Contravariant ((:.:) f g) # Methodscontramap :: (a -> b) -> (f :.: g) b -> (f :.: g) a #(>$) :: b -> (f :.: g) b -> (f :.: g) a # # Methodscontramap :: (a -> b) -> Const * a b -> Const * a a #(>$) :: b -> Const * a b -> Const * a a # # Methodscontramap :: (a -> b) -> Alt * f b -> Alt * f a #(>$) :: b -> Alt * f b -> Alt * f a # # Methodscontramap :: (a -> b) -> Reverse * f b -> Reverse * f a #(>$) :: b -> Reverse * f b -> Reverse * f a # # Methodscontramap :: (a -> b) -> Backwards * f b -> Backwards * f a #(>$) :: b -> Backwards * f b -> Backwards * f a # Contravariant m => Contravariant (WriterT w m) # Methodscontramap :: (a -> b) -> WriterT w m b -> WriterT w m a #(>$) :: b -> WriterT w m b -> WriterT w m a # Contravariant m => Contravariant (WriterT w m) # Methodscontramap :: (a -> b) -> WriterT w m b -> WriterT w m a #(>$) :: b -> WriterT w m b -> WriterT w m a # Contravariant m => Contravariant (StateT s m) # Methodscontramap :: (a -> b) -> StateT s m b -> StateT s m a #(>$) :: b -> StateT s m b -> StateT s m a # Contravariant m => Contravariant (StateT s m) # Methodscontramap :: (a -> b) -> StateT s m b -> StateT s m a #(>$) :: b -> StateT s m b -> StateT s m a # # Methodscontramap :: (a -> b) -> IdentityT * f b -> IdentityT * f a #(>$) :: b -> IdentityT * f b -> IdentityT * f a # Contravariant m => Contravariant (ExceptT e m) # Methodscontramap :: (a -> b) -> ExceptT e m b -> ExceptT e m a #(>$) :: b -> ExceptT e m b -> ExceptT e m a # Contravariant m => Contravariant (ErrorT e m) # Methodscontramap :: (a -> b) -> ErrorT e m b -> ErrorT e m a #(>$) :: b -> ErrorT e m b -> ErrorT e m a # # Methodscontramap :: (a -> b) -> Constant * a b -> Constant * a a #(>$) :: b -> Constant * a b -> Constant * a a # (Contravariant f, Functor g) => Contravariant (ComposeCF f g) # Methodscontramap :: (a -> b) -> ComposeCF f g b -> ComposeCF f g a #(>$) :: b -> ComposeCF f g b -> ComposeCF f g a # (Functor f, Contravariant g) => Contravariant (ComposeFC f g) # Methodscontramap :: (a -> b) -> ComposeFC f g b -> ComposeFC f g a #(>$) :: b -> ComposeFC f g b -> ComposeFC f g a # Contravariant f => Contravariant (M1 i c f) # Methodscontramap :: (a -> b) -> M1 i c f b -> M1 i c f a #(>$) :: b -> M1 i c f b -> M1 i c f a # (Contravariant f, Contravariant g) => Contravariant (Sum * f g) # Methodscontramap :: (a -> b) -> Sum * f g b -> Sum * f g a #(>$) :: b -> Sum * f g b -> Sum * f g a # (Contravariant f, Contravariant g) => Contravariant (Product * f g) # Methodscontramap :: (a -> b) -> Product * f g b -> Product * f g a #(>$) :: b -> Product * f g b -> Product * f g a # Contravariant m => Contravariant (ReaderT * r m) # Methodscontramap :: (a -> b) -> ReaderT * r m b -> ReaderT * r m a #(>$) :: b -> ReaderT * r m b -> ReaderT * r m a # (Functor f, Contravariant g) => Contravariant (Compose * * f g) # Methodscontramap :: (a -> b) -> Compose * * f g b -> Compose * * f g a #(>$) :: b -> Compose * * f g b -> Compose * * f g a # Contravariant m => Contravariant (RWST r w s m) # Methodscontramap :: (a -> b) -> RWST r w s m b -> RWST r w s m a #(>$) :: b -> RWST r w s m b -> RWST r w s m a # Contravariant m => Contravariant (RWST r w s m) # Methodscontramap :: (a -> b) -> RWST r w s m b -> RWST r w s m a #(>$) :: b -> RWST r w s m b -> RWST r w s m a # phantom :: (Functor f, Contravariant f) => f a -> f b # 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 it's 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  # Operators (>$<) :: Contravariant f => (a -> b) -> f b -> f a infixl 4 #

This is an infix alias for contramap

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

This is an infix version of contramap with the arguments flipped.

($<) :: Contravariant f => f b -> b -> f a infixl 4 # This is >$ with its arguments flipped.

# Predicates

newtype Predicate a #

Constructors

 Predicate FieldsgetPredicate :: a -> Bool

Instances

 # A Predicate is a Contravariant Functor, because contramap can apply its function argument to the input of the predicate. Methodscontramap :: (a -> b) -> Predicate b -> Predicate a #(>$) :: b -> Predicate b -> Predicate a # # Methodslose :: (a -> Void) -> Predicate a #choose :: (a -> Either b c) -> Predicate b -> Predicate c -> Predicate a # # Methodsdivide :: (a -> (b, c)) -> Predicate b -> Predicate c -> Predicate a # # Comparisons newtype Comparison a # 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  Comparison FieldsgetComparison :: a -> a -> Ordering Instances  # A Comparison is a Contravariant Functor, because contramap can apply its function argument to each input of the comparison function. Methodscontramap :: (a -> b) -> Comparison b -> Comparison a #(>$) :: b -> Comparison b -> Comparison a # # Methodslose :: (a -> Void) -> Comparison a #choose :: (a -> Either b c) -> Comparison b -> Comparison c -> Comparison a # # Methodsdivide :: (a -> (b, c)) -> Comparison b -> Comparison c -> Comparison a # # Methods(<>) :: Comparison a -> Comparison a -> Comparison a #sconcat :: NonEmpty (Comparison a) -> Comparison a #stimes :: Integral b => b -> Comparison a -> Comparison a # # Methodsmappend :: Comparison a -> Comparison a -> Comparison a #mconcat :: [Comparison a] -> Comparison a #

Compare using compare

# Equivalence Relations

newtype Equivalence a #

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 b and getEquivalence f b c are both True then so is getEquivalence f a c

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

Constructors

 Equivalence FieldsgetEquivalence :: a -> a -> Bool

Instances