[Haskell-cafe] Simple way to do something like ArrowChoice.right on a Conduit? (version 1.0.0)

Joey Adams joeyadams3.14159 at gmail.com
Wed Mar 6 04:48:48 CET 2013


On Tue, Mar 5, 2013 at 9:24 AM, Michael Snoyman <michael at snoyman.com> wrote:

> ...
> I'm not sure if I entirely understand your use case, but in general it
> should be possible to have multiple Conduits running one after the other.
> Here's an example of restarting an accumulator after every multiple of 5:
>
>
> https://www.fpcomplete.com/user/snoyberg/random-code-snippets/multiple-conduits
>
>
Neat.  I didn't think to do that with plain Conduits.  I did realize I
could use a resumable conduit as a "temporary filter" (basically what your
example does).  This suggests that a resumable conduit can be used in any
consumer (Conduit or Sink), not just a sink.  Perhaps it can even be used
in a producer, though different operators would be needed (+$= instead of
=$+).

In my compression example, the incoming message sink needs to feed chunks
of compressed data to a zlib conduit.  It can't just hand full control of
the input to zlib; it has to decode messages, and only send CompressedData
messages through zlib.  I need a resumable conduit for that.

Here's my current implementation of resumable conduits [1].  I don't know
much about conduit finalizers; I mostly followed 'connectResume' and
'pipeL'.

The main wrinkle is that when the ResumableConduit receives an upstream
terminator, it forwards it to the sink, rather than telling the conduit
that the stream ended.  This allows the conduit to be reused.  Only when we
finish the ResumableConduit () do we send it the stream terminator.

I'll continue toying with this.  It might be possible to factor out
terminator forwarding, and generalize connectResume to support resumable
sources, conduits, and sinks.

Thanks for the help,
-Joey

 [1]:
https://github.com/joeyadams/hs-resumable-conduit/blob/master/ResumableConduit.hs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130305/c0d87bc0/attachment.htm>


More information about the Haskell-Cafe mailing list