A contravariant functor $F : \mathsf{Type}^{\text{op}} \to \mathsf{Type}$. Unlike a covariant functor which preserves morphism direction, a contravariant functor reverses it: given $f : \alpha \to \beta$, we obtain
$$\text{contramap}\; f : F\;\beta \to F\;\alpha$$
- contramap {α β : Type u} : (α → β) → F β → F α
Map contravariantly: given $f : \alpha \to \beta$, produce $\text{contramap}\;f : F\;\beta \to F\;\alpha$.
Instances
Laws for a lawful contravariant functor:
- Identity: $\text{contramap}\;\text{id} = \text{id}$
- Composition: $\text{contramap}\;(f \circ g) = \text{contramap}\;g \circ \text{contramap}\;f$
Note the reversal in the composition law — this is dual to the covariant functor law.
Identity law: $\text{contramap}\;\text{id}\;x = x$.
- contramap_comp {β γ α : Type u} (f : β → γ) (g : α → β) (x : F γ) : Contravariant.contramap (f ∘ g) x = Contravariant.contramap g (Contravariant.contramap f x)
Composition law: $\text{contramap}\;(f \circ g)\;x = \text{contramap}\;g\;(\text{contramap}\;f\;x)$.
Instances
A predicate $P : \alpha \to \text{Prop}$, wrapped as a contravariant functor.
Given $f : \alpha \to \beta$ and a predicate $P$ on $\beta$, the contramapped predicate is $P \circ f$, i.e., $(\text{contramap}\;f\;P)(x) = P(f(x))$.
- getPredicate : α → Prop
Instances For
Contravariant instance for Predicate:
$\text{contramap}\;f\;P = P \circ f$.
Equations
- Data.Functor.instContravariantPredicate = { contramap := fun {α β : Type ?u.10} (f : α → β) (p : Data.Functor.Predicate β) => { getPredicate := p.getPredicate ∘ f } }
Predicate is a lawful contravariant functor — both laws hold definitionally.
An equivalence relation $R : \alpha \to \alpha \to \text{Prop}$, wrapped as a contravariant functor.
Given $f : \alpha \to \beta$ and an equivalence $R$ on $\beta$, the contramapped equivalence is: $(\text{contramap}\;f\;R)(a, b) = R(f(a), f(b))$.
- getEquivalence : α → α → Prop
Instances For
Contravariant instance for Equivalence:
$(\text{contramap}\;f\;R)(a, b) = R(f(a),\, f(b))$.
Equations
- One or more equations did not get rendered due to their size.
Equivalence is a lawful contravariant functor — both laws hold definitionally.