Here is how we can define KleisliFunctor
:
class (Monad m, Functor f) => KleisliFunctor m f where
kmap :: (a -> m b) -> f a -> f b
kmap f = kjoin . fmap f
kjoin :: f (m a) -> f a
kjoin = kmap id
Does this type class
class (Functor f, Monad m) => Absorb f m where
(>>~) :: f a -> (a -> m b) -> m b
a >>~ f = ajoin $ fmap f a
ajoin :: f (m a) -> m a
ajoin a = a >>~ id
fit somewhere into category theory? What are the laws? Are they
a >>~ g . f === fmap f a >>~ g
a >>~ (f >=> g) === a >>~ f >>= g
?
This is a speculative answer. Proceed with caution.
Let's first consider
KleisliFunctor
, focusing on the bind-like arrow mapping:For this to actually be a functor from the Kleisli category of
m
to Hask,kmap
has to follow the relevant functor laws:The fact that there are two
Functor
s involved makes things a little unusual, but not unreasonable -- for instance, the laws do hold formapMaybe
, which is the first concrete example theKleisliFunctor
post alludes to.As for
Absorb
, I will flip the bind-like method for the sake of clarity:If we are looking for something analogous to
KleisliFunctor
, a question that immediately arises is which category would have functions of typef a -> m b
as arrows. It certainly cannot be Hask, as its identity (of typef a -> m a
) cannot beid
. We would have to figure out not only identity but also composition. For something that is not entirely unlikeMonad
...... the only plausible thing I can think of right now is having a monad morphism as
idAbsorb
and using a second monad morphism in the opposite direction (that is, fromm
tof
) so thatcompAbsorb
can be implemented by applying the first function, then going back tof
and finally applying the second function. We would need to work that out in order to see if my assumptions are appropriate, if this approach works, and if it leads to something useful for your purposes.