[web-devel] Monad transformers with Warp/WAI

Michael Snoyman michael at snoyman.com
Sat May 16 19:15:33 UTC 2015


On Sat, May 16, 2015 at 10:05 PM Alex <alex323 at gmail.com> wrote:

> On Sat, 16 May 2015 18:30:31 +0000
> Michael Snoyman <michael at snoyman.com> wrote:
>
> > Typically it would look something like this:
> >
> > myApp :: AppConfig -> Application
> >
> > main = do
> >   appConfig <- getAppConfig
> >   run 3000 $ myApp appConfig
> >
> > Within myApp, you can now access the AppConfig value and use
> > runReaderT to unwrap your MyApp transformer.
> >
>
> Is a consequence of this design that I have to use runReaderT every
> time I want to use a function of the type (Foo -> MyApp Bar) from within
> myApp? Is it better/easier to simply rewrite the all functions myApp
> calls so that they accept an AppConfig parameter instead of returning a
> MyApp Bar?
>
> --
> Alex
>

That's one approach. You can also do something like:

myApp appConfig req respond = flip runReaderT appConfig $ do
    someFunc
    ...

someFunc :: MyApp ()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/web-devel/attachments/20150516/aa1d79b6/attachment.html>


More information about the web-devel mailing list