[web-devel] Upgrading from WAI 1.4.1 to 2.0.0, Monad / ResourceT issues

Michael Snoyman michael at snoyman.com
Mon Dec 9 06:36:23 UTC 2013


There are two different approaches you could use:

1. Modify the source so that its base monad is ResourceT IO. You can do
that using hoist, e.g.:

    let newSource = hoist lift (requestBody req)

2. In a situation like this, you don't really need ResourceT at all.
Instead, using withFile and sinkHandle would be sufficient:

    withFile ("source" </> fromText name) WriteMode $ \h ->
        requestBody req $$ sinkHandle h

I'd recommend going for (2), as IMO it's a little bit clearer what's going
on, and is slightly more efficient.

Michael


On Sun, Dec 8, 2013 at 9:44 PM, Leif Warner <abimelech at gmail.com> wrote:

> Trying to upgrade this code from WAI 1.4.1 to 2.0.0.  On one hand, I don't
> have to liftIO the IO action on line 23 anymore.  On the other, this line
> that writes the request body to a file seems to be giving me some trouble
> now:
> https://github.com/LeifW/online-typechecker/blob/master/index.hs#L22
>
>     No instance for (MonadResource IO) arising from a use of `sinkFile'
>     Possible fix: add an instance declaration for (MonadResource IO)
>     In the second argument of `($$)', namely
>       `sinkFile ("sources" </> fromText name)'
>     In a stmt of a 'do' block:
>       requestBody req $$ sinkFile ("sources" </> fromText name)
>
> If I put a "runResouceT" in front of that, like "runResourceT $
> requestBody req $$ sinkFile ("sources" </> fromText name)", I get
>
>     Couldn't match type `IO' with `ResourceT IO'
>     Expected type: Data.Conduit.Internal.Source
>                      (ResourceT IO) Data.ByteString.Internal.ByteString
>       Actual type: Data.Conduit.Internal.Source
>                      IO Data.ByteString.Internal.ByteString
>     In the return type of a call of `requestBody'
>     In the first argument of `($$)', namely `requestBody req'
>     In the second argument of `($)', namely
>       `requestBody req $$ sinkFile ("sources" </> fromText name)'
>
> Any pointers?
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20131209/ff79dbcf/attachment.html>


More information about the web-devel mailing list