I came up with the same

     foo :: Int ->  Pipe Int (Maybe Int, Int) IO () 
     foo n = loop (Seq.replicate n Nothing) where
        loop s = do x <- await
                    let s' :> a = viewr s
                    yield (a,x)
                    loop (Just x <| s')
 
modulo a tasteless pattern match. 

Maybe I should start a different thread, but what bugged me about it was 
the `printer` bit.
When we have a very fast process that prints, it all goes to fast for my 
terminal to 
handle.  So I looked a little into builders.  I looked at the 
conduit-blaze-builder package
without much light; in the end I made a little beginning at figuring out 
the Builder and
Builder.Internal modules of more recent `bytestring` s.  

The following is very rough and only defines pipes :: `Pipes Builder 
ByteString IO r`
when I was hoping for `Consumer ByteString IO r` and the like. and since it 
uses
new bytestrings, Gabriel might not be able to test it:

https://github.com/michaelt/pipes-builder-shabby
>

I ran Daniels program 3 ways in test/Test.hs

- once with `for pipe (lift.print)` ("printer");
- once for `for (pipe >-> buildPair) (lift . hPutBuilder stdout)` where
     `buildPair` was a simple pipe for showing-in-terms-of-builders 
     without mediation of strings ("builder")
- once with "simple :: Pipe Builder IO ByteString" as 
    `for (pipe >-> buildPair >-> simple) (lift . B.putStr)` ("simple")


    -- time ./test 1000000 program  (> /dev/null)
    -- shabby  0m3.517s                  0m0.605s
    -- builder 0m9.532s                  0m0.565s
    -- printer 0m10.864s                 0m1.340s

    -- time ./test 5000000 program  
    -- shabby  0m18.894s               0m2.734s
    -- builder 0m48.195s               0m2.927s
    -- printer 0m55.615s               0m6.631s

The first column has the program spilling into stdout,
the other into /dev/null.  The backlog gets worse the
longer the program, so though when sent to /dev/null
a straightforward use of builder seems no better, 
when sent to stdin it is increasingly crushed by 
'proper' -- or so far shabby -- use of builders.
 
I'm not sure what to make of it. Maybe it could use more study.

Michael

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to