[Haskell-cafe] Fighting the monad stack, MonadIO

Ryan Ingram ryani.spam at gmail.com
Thu Apr 10 13:09:01 EDT 2008


Assuming you have "ioAction :: IO x -> BrowserAction x"
(from http://homepages.paradise.net.nz/warrickg/haskell/http/#browser)

you can do:

> instance MonadIO BrowserAction where liftIO = ioAction

Then you can derive MonadIO with GHC's newtype deriving.

Alternatively, you can implement it directly on your type:

> instance MonadIO RBAction where
>   liftIO = RBAction . lift . lift . ioAction

This just inserts the proper number of "lift"s to bring the
BrowserAction through your monad transformer stack, and then wraps it
with your newtype constructor.

On Thu, Apr 10, 2008 at 7:50 AM, Adam Smyczek <adam.smyczek at gmail.com> wrote:
> For a small webapi binding I try to implement a session like monad
>  by building a stack including BrowserAction from Network.Browser
>  module as following:
>
>  newtype RBAction a = RBAction
>     { exec :: ErrorT String (StateT RBState BrowserAction) a }
>     deriving (Functor, Monad, MonadState RBState)
>
>  I would like the RBAction to implement MonadIO as well,
>  but fight with the liftIO function for hours now, without success.
>  Any idea how the implementation of liftIO could look like?
>
>  Thanks for help,
>  Adam
>
>
>  _______________________________________________
>  Haskell-Cafe mailing list
>  Haskell-Cafe at haskell.org
>  http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list