<p dir="ltr">No problem</p>
<br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 7, 2017, 10:02 PM Pieter Laeremans <<a href="mailto:pieter@laeremans.org">pieter@laeremans.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Thans a lot!</div></div><div dir="auto"><div><br><br>Pieter Laeremans</div></div><div dir="auto"><div><br>On 7 Aug 2017, at 20:15, Michael Snoyman <<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>> wrote:<br><br></div></div><div dir="auto"><blockquote type="cite"><div><div dir="ltr"><div>Because ConduitM is based on continuations, you can't safely acquire resources inside of it. In order to make safe allocations, you need to use ResourceT. I wrote a blog post two months ago with a lot more information on ResourceT:</div><div><br></div><div><a href="https://www.fpcomplete.com/blog/2017/06/understanding-resourcet" target="_blank">https://www.fpcomplete.com/blog/2017/06/understanding-resourcet</a></div><div><br></div><div>Because of this, you cannot use `withResource`. The error message you're getting is confusing, but this is where it's coming from: because of its continuations, ConduitM cannot provide a MonadBaseControl instance. Instead, you'll need to use the `takeResource` and either `destroyResource` or `putResource` functions, plus something like `bracketP` or `allocate`.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 7, 2017 at 3:57 PM, Pieter Laeremans <span dir="ltr"><<a href="mailto:pieter@laeremans.org" target="_blank">pieter@laeremans.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I would like to combine a "Connection Pool" with the conduit library.<br>
<br>
I have an application were a stream of results from a web api needs to<br>
be analysed and stored in a database.<br>
Since the analysis is composed of different parts, I combine some parts<br>
together ( .|)<br>
<br>
Some of those parts need a database connection to do their work.<br>
Initially I created a Connection and passed it around to each part that<br>
needed it, this is sub-optimal. So I wanted to try the "resource-pool"<br>
library to address this problem.<br>
(<a href="https://hackage.haskell.org/package/resource-pool" rel="noreferrer" target="_blank">https://hackage.haskell.org/package/resource-pool</a>)<br>
<br>
So instead of a Connection I pass around a (Pool Connection) But I run<br>
into problems , and I don't know how to fix them.<br>
<br>
Here is a simple snippet of code that demonstrates the problem:<br>
<br>
<br>
-------------------------------------------<br>
{-# LANGUAGE RankNTypes #-}<br>
<br>
module Lib where<br>
<br>
import Data.Pool<br>
import Database.HDBC<br>
import Database.HDBC.ODBC<br>
import Data.Conduit<br>
import Conduit<br>
<br>
createConnectionPool :: Pool Connection<br>
createConnectionPool = undefined<br>
<br>
processFoo :: Pool Connection -> Consumer String IO ()<br>
processFoo pool = withResource pool $ \conn -> do<br>
                                                 mapM_C print<br>
<br>
-------------------------<br>
<br>
I can not get this to compile:<br>
<br>
src/Lib.hs:15:19: error:<br>
    • No instance for (MonadBaseControl IO (ConduitM String o IO))<br>
        arising from a use of ‘withResource’<br>
    • In the expression: withResource pool<br>
      In the expression:<br>
        withResource pool $ \ conn -> do { mapM_C print }<br>
      In an equation for ‘processFoo’:<br>
          processFoo pool = withResource pool $ \ conn -> do { mapM_C<br>
          print }<br>
<br>
But I have no Idea how to tackle this problem.  Any suggestions ?<br>
<br>
Thanks,<br>
<br>
Pieter<br>
<span class="m_7734718579128789150HOEnZb"><font color="#888888"><br>
--<br>
  Pieter Laeremans<br>
  <a href="mailto:pieter@laeremans.org" target="_blank">pieter@laeremans.org</a><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</font></span></blockquote></div><br></div>
</div></blockquote></div></blockquote></div>