These instances exist already as Codensity and Density but they could be included for right/left Kan extensions of functors along themselves.
instance f₁ ~ f₂ => Applicative (Ran f₁ f₂) where
pure x = Ran (\k -> k x)
Ran f <*> Ran g = Ran (\bfr -> f (\ab -> g (bfr . ab)))
instance f₁ ~ f₂ => Monad (Ran f₁ f₂) where
return = pure
m >>= k = Ran (\c -> runRan m (\a -> runRan (k a) c))
-- etc.
and
instance f₁ ~ f₂ => Comonad (Lan f₁ f₂) where
duplicate (Lan f ws) = Lan (Lan f) ws
extract (Lan f a) = f a
-- etc.
Annoyingly the same can be done for Yoneda / Coyoneda
instance (Identity ~ id, Applicative f) => Applicative (Ran id f) where
pure a = Ran (\f -> pure (runIdentity (f a)))
-- ...
instance Identity ~ id => Foldable (Codensity id) where
foldMap f = foldMap f . lowerYoneda . ranToYoneda . codensityToRan
which overlaps and looks icky, is this a horrible idea?
These instances exist already as
Codensity
andDensity
but they could be included for right/left Kan extensions of functors along themselves.and
Annoyingly the same can be done for
Yoneda
/Coyoneda
which overlaps and looks icky, is this a horrible idea?