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

Michael Snoyman michael at snoyman.com
Wed Mar 6 07:42:07 CET 2013


On Wed, Mar 6, 2013 at 5:48 AM, Joey Adams <joeyadams3.14159 at gmail.com>wrote:

> 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.
>
>
I'm still not sure I follow this. In the example I linked to, the go
function within breaker could arbitrarily modify the data before it gets
passed on to the inner Conduit. So it seems like it should be possible to
achieve your goals this way. But I may just not fully understand your use
case.

Michael


> 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/20130306/79a2643a/attachment.htm>


More information about the Haskell-Cafe mailing list