简体   繁体   中英

Is there an “ApplicativeIO” class?

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 (ie, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM