Note that there are some explanatory texts on larger screens.

plurals
  1. POpipes 3.0 : non linear topologies
    primarykey
    data
    text
    <p>I am having a look at the pipes 3.0 package for stream processing. <a href="http://hackage.haskell.org/packages/archive/pipes/3.0.0/doc/html/Control-Proxy-Tutorial.html" rel="noreferrer">The tutorial</a> is very well done and very clear, except that I cannot wrap my head around the "zip and merge" section.</p> <p>My goal is to combine pipes a bit like ArrowChoice allows to do:</p> <ul> <li>I have a unique producer of Either a a</li> <li>I would like to apply a first pipe to Left values and another one to Right values</li> <li>I would then like to merge the results, and continue piping</li> </ul> <pre><code> +----------+ +------+ - filterLeft -> pipe1 -> +------------+ | producer | - (Either a a) -> | fork | | mergeD (?) | +----------+ +------+ - filterRight -> pipe2 -> +------------+ </code></pre> <p>I define <code>fork</code> like in the tutorial:</p> <pre><code>fork () = runIdentityP . hoist (runIdentityP . hoist runIdentityP) $ forever $ do a &lt;- request () lift $ respond a lift $ lift $ respond a oddOrEven x = if odd x then Left x else Right x producer = fromListS [1..0] &gt;-&gt; mapD oddOrEven isLeft (Left _) = True isLeft (Right _) = False isRight = not . isLeft filterLeft = filterD isLeft filterRight = filterD isRight pipe1 = mapD (\x -&gt; ("seen on left", x)) pipe2 = mapD (\x -&gt; ("seen on right", x)) p1 = producer &gt;-&gt; fork </code></pre> <p>The problem is that I cannot make the types right. The tutorial seems only to show how to run the inner (lifted) pipe chain as a self contained session, but I would like to be able to reinject its values to the pipe, not just apply an effect on them. I of course tried to follow the types, but they get a bit hairy very quickly.</p> <p>Does Anyone can help me on this ? Thanks in advance.</p> <p>(PS: an example of this kind of topology would be a nice addition to the tutorial, or even better a section on how to emulate the <code>Control.Arrow</code> stuff using pipes)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload