Is there somewhere in Hackage a typeclass analogous to MonadIO
but for Applicative
s, that allows one to easily lift IO
actions to "applicative composition stacks" based on IO
?
If such a typeclass existed, would it be made obsolete by the implementation of the Applicative-Monad Proposal? Does the proposal involve a relaxation on the Monad
constraint for MonadIO
?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With