There was a related discussion on haskell-cafe a year ago. In the Reddit comments I gave an example of a natural transformation (g
) from IO to another monad that is an applicative functor morphism (i.e., satisfies the laws that Gabriel Gonzalez mentioned) but is not a monad morphism (it does not satisfy the additional law relating to >>=
). So, even in a world with AMP, ApplicativeIO m
and MonadIO m
are really different things, even when m
is a Monad
!
In an ideal world you'd have a setup like this:
class Functor f => FunctorIO f where
liftIO :: IO a -> f a
-- such that liftIO is a natural transformation (automatic, by parametricity)
class (Applicative f, FunctorIO f) => ApplicativeIO f where
-- ... and liftIO is an applicative functor morphism
class (Monad f, ApplicativeIO f) => MonadIO f where
-- ... and liftIO is a monad morphism
and magical fairies would define ApplicativeIO
and MonadIO
instances exactly when the corresponding laws were satisfied.
Monad
constraint is worth considering. – Tom Ellis Sep 26 '14 at 17:58liftAIO (pure r) = pure r
andliftAIO (f <*> x) = liftAIO f <*> liftAIO x
– Gabriel Gonzalez Sep 26 '14 at 20:15Monad
constraint forMonadIO
would be problematic if for no other reason than that there is a lot of code out there with type signatures like(MonadIO m) => ... -> m ...
that requiresm
to be aMonad
(for reasons unrelated toliftIO
). ButMonadIO m
is not equivalent to(Monad m, ApplicativeIO m)
either, see my answer below. – Reid Barton Sep 27 '14 at 0:57