Documentation

Hale.Base.Data.Functor.Contravariant

class Data.Functor.Contravariant (F : Type u → Type v) :
Type (max (u + 1) v)

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:

    1. Identity: $\text{contramap}\;\text{id} = \text{id}$
    2. 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.

    Instances
      structure Data.Functor.Predicate (α : Type u) :

      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
        @[implicit_reducible]

        Contravariant instance for Predicate: $\text{contramap}\;f\;P = P \circ f$.

        Equations

        Predicate is a lawful contravariant functor — both laws hold definitionally.

        structure Data.Functor.Equivalence (α : Type u) :

        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
          @[implicit_reducible]

          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.