Lets say I have the following
import Control.Category (Category, (.), id)
data Invertible a b = Invertible (a -> b) (b -> a)
instance Category Invertible where
id = Invertible Prelude.id Prelude.id
(Invertible f f') . (Invertible g g') =
Invertible (f Prelude.. g) (g' Prelude.. f')
invert (Invertible x y) = Invertible y x
Note that the following is true:
invert (g . f) == invert f . invert g
This structure seems very similar to a contravariant functor (wikipedia), as it follows the same axiom:
F(g . f) = F(f) . F(g)
In my case, F
is simply invert
.
I looked at Data.Functor.Contravariant.contramap, which has a function of the type:
(a -> b) -> f b -> f a
But I didn't know how'd I'd implement that in my situation. For example, I can't work out a sensible choice for f
, and in my situation, there's no function a -> b
, just invert
.
However, invert
nevertheless fits the mathematical axiom of a contravariant functor, so I'm thinking I can fit this into some existing class, but I just can't find which one and how to do it. Any help or pointers would be appreciated.
invert
is a contravariant endofunctor in the category ofInvertible
whereasContravariant f
is a contravariant endofunctor in the category ofHask
. – VerveIso s t a b = forall f p . (Functor f, Profunctor p) => p a (f b) -> p s (f t)
andIso' a b = Iso a a b b
.Iso'
ends up being isomorphic to your type. This doesn't relate to your question; I just thought you might find it interesting. – Vaulting