[Haskell-cafe] Can't get my head round monad transformers

Martijn van Steenbergen martijn at van.steenbergen.nl
Wed Sep 2 05:53:12 EDT 2009

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!


More information about the Haskell-Cafe mailing list