Can't get my head round monad transformers

I'm trying to add a state monad onto the IO monad for use in a happstack application. I thought this should involve using StateT and Happstack.Server.SimpleHTTP.simpleHTTP', but I can't figure out how to plumb it all together. Any tips will be welcome. -- Colin Adams Preston, Lancashire, ENGLAND

Maybe the chapter on monad transformers in RWH can help?
http://book.realworldhaskell.org/read/monad-transformers.html
On Tue, Sep 1, 2009 at 7:34 PM, Colin
Adams
I'm trying to add a state monad onto the IO monad for use in a happstack application. I thought this should involve using StateT and Happstack.Server.SimpleHTTP.simpleHTTP', but I can't figure out how to plumb it all together. Any tips will be welcome.
-- Colin Adams Preston, Lancashire, ENGLAND _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi Colin, Colin Adams wrote:
I'm trying to add a state monad onto the IO monad for use in a happstack application. I thought this should involve using StateT and Happstack.Server.SimpleHTTP.simpleHTTP', but I can't figure out how to plumb it all together. Any tips will be welcome.
I'm not familiar with Happstack, but looking at the documentation:
simpleHTTP' :: (Monad m, ToMessage b) => (m (Maybe (Either Response a, FilterFun Response)) -> IO (Maybe (Either Response b, FilterFun Response))) -> Conf -> ServerPartT m a -> IO ()
Do I understand correctly you will be working with a
myAction :: ServerPartT (StateT S IO) A ?
Then it seems that you may call simpleHTTP' like this:
simpleHTTP' (\action -> evalStateT action initState) myConf myAction
The first argument (the lambda) has type
forall a m. Monad m => StateT S m a -> m a which can be specialised to what simpleHTTP' is expecting.
I hope this helps! Martijn.

Thanks. That was all I needed to sort it out.
2009/9/2 Martijn van Steenbergen
Hi Colin,
Colin Adams wrote:
I'm trying to add a state monad onto the IO monad for use in a happstack application. I thought this should involve using StateT and Happstack.Server.SimpleHTTP.simpleHTTP', but I can't figure out how to plumb it all together. Any tips will be welcome.
I'm not familiar with Happstack, but looking at the documentation:
simpleHTTP' :: (Monad m, ToMessage b) => (m (Maybe (Either Response a, FilterFun Response)) -> IO (Maybe (Either Response b, FilterFun Response))) -> Conf -> ServerPartT m a -> IO ()
Do I understand correctly you will be working with a
myAction :: ServerPartT (StateT S IO) A
?
Then it seems that you may call simpleHTTP' like this:
simpleHTTP' (\action -> evalStateT action initState) myConf myAction
The first argument (the lambda) has type
forall a m. Monad m => StateT S m a -> m a
which can be specialised to what simpleHTTP' is expecting.
I hope this helps!
Martijn.
-- Colin Adams Preston, Lancashire, ENGLAND
participants (3)
-
Colin Adams
-
Martijn van Steenbergen
-
Peter Verswyvelen