Don't understand the correct way to compose "meta" producers.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Don't understand the correct way to compose "meta" producers.

Daniel Hill
Hey guys,

the types of Pipes.Zlib/Gzip are in the form Producer -> Producer, if I was to implement such a library my first though would be to make them Pipes, so you could compose them as such ` producer >-> compress >-> consumer`.

instead i have to use the form `for producer (\x -> compress (yield x)) >-> consumer` which works correctly for my current project, but I'm left wondering why I have to perform such gymnastics to turn them in to pipes, something tells me that i need  to use ~> but even if I can get it to compile, I don't get any output.

So can anyone give me some insight to this, thanks

- Daniel

--
Reply | Threaded
Open this post in threaded view
|

Re: Don't understand the correct way to compose "meta" producers.

Gabriel Gonzalez
There is no way to turn a `Producer -> Producer` into a `Pipe` in general.  Usually the point of writing a function of type `Producer -> Producer` is so that you can detect and handle the end of input.  If your `compress` function is doing something similar then something like `for producer (compress . yield)` might misbehave because it will treat each value yielded by the `producer` as having its own end of input.

On Apr 13, 2017, at 9:32 PM, Daniel Hill <[hidden email]> wrote:

Hey guys,

the types of Pipes.Zlib/Gzip are in the form Producer -> Producer, if I was to implement such a library my first though would be to make them Pipes, so you could compose them as such ` producer >-> compress >-> consumer`.

instead i have to use the form `for producer (\x -> compress (yield x)) >-> consumer` which works correctly for my current project, but I'm left wondering why I have to perform such gymnastics to turn them in to pipes, something tells me that i need  to use ~> but even if I can get it to compile, I don't get any output.

So can anyone give me some insight to this, thanks

- Daniel

--

--