We can write the following Contravariant instances:
instance Contravariant (Forget r a) where
contramap _ = coerce
-- or: contramap _ (Forget ra) = Forget ra
and:
instance Contravariant f => Contravariant (Star f a) where
contramap f (Star g) = Star (contramap f . g)
profunctors already depends on contravariant, so this does not change the dependency footprint at all.
These are useful when implementing profunctor optics (example using the new QuantifiedConstraints extension):
type Getter s t a b = forall p. (Profunctor p, forall x. Contravariant (p x)) => p a b -> p s t
to :: (s -> a) -> Getter s t a b
to get = (() >$) . dimap get (const ())
type Getting r s t a b = Forget r a b -> Forget r s t
view :: Getting a s t a b -> s -> a
view l = runForget (l (Forget id))
I will create a PR adding these instances tomorrow, unless they are intentionally left out.
We can write the following
Contravariant
instances:and:
profunctors
already depends oncontravariant
, so this does not change the dependency footprint at all.These are useful when implementing profunctor optics (example using the new
QuantifiedConstraints
extension):I will create a PR adding these instances tomorrow, unless they are intentionally left out.