Zulip Chat Archive
Stream: Is there code for X?
Topic: Contravariant functor
Léo Lessa (Jan 22 2025 at 20:28):
Does mathlib have a "contravariant functor" class (outside CategoryTheory
), akin to Haskell's Contravariant? That is, something like:
class ContravariantFunctor (f : Type u → Type v) where
contramap : {α β : Type u} → (α → β) → f β → f α
Edward van de Meent (Jan 22 2025 at 22:14):
@loogle "contravariant"
loogle (Jan 22 2025 at 22:14):
:search: Contravariant, ContravariantClass, and 42 more
Adam Topaz (Jan 22 2025 at 22:15):
I don’t think we have this
Edward van de Meent (Jan 22 2025 at 22:17):
From the looks of it, we don't, no. We only seem to have contravariant relations(?)
Chris Wong (Jan 22 2025 at 22:26):
What's your use case for the class? If it's composing comparison functions, you might be interested in onFun
Chris Wong (Jan 22 2025 at 22:27):
@loogle onFun
loogle (Jan 22 2025 at 22:27):
:exclamation: unknown identifier 'onFun'
Did you mean "onFun"
, Function.onFun
, or something else?
Léo Lessa (Jan 22 2025 at 23:42):
A generic use case could be to characterize classes Class (i : Type u)
whose methods functorially depend on a type i
as input. For example, the class
class ExampleClass (i : Type u) where
method1 : i → ℕ
...
could be an instance of ContravariantFunctor
as
instance inst : ContravariantFunctor ExampleClass where
contramap (f : i → j) ej := { method1 : j → ℕ := ej.method1 ∘ f, ...}
I personally encountered a case just like the one above when defining a congr
theorem here. In that case, it should have followed that, if f
is a contravariant functor, then α ≃ β
implies f α ≃ f β
, which would be the contravariant version of Functor.mapEquiv
. Instead, I had to write it by hand.
Last updated: May 02 2025 at 03:31 UTC