I noticed that `chunksOf` involves a very complicated double use of `next` (it uses `splitAt` which is also defined with `next`). `next` basically forces each step into the base monad.
It's not a miracle, but if I reimplement `chunksOf` using Pipes.Internal explicitly, the 'idiomatic' program goes from real 0m0.209s to real 0m0.097s (I was chunking at 10 for some reason) Not too bad. Does this work better for you Tran? import qualified Pipes.Internal as I chunksOf :: Monad m => Int -> Lens (Producer a' m x) (Producer a m x) (FreeT (Producer a' m) m x) (FreeT (Producer a m) m x) chunksOf n0 k p0 = fmap concats (k (_chunksOf_ p0)) where _chunksOf_ p = case p of I.Pure r -> return r I.Request v _ -> I.closed v I.M m -> FreeT $ m >>= runFreeT . _chunksOf_ x -> FreeT $ return $ Free $ fmap _chunksOf_ (to n0 x) to n p = if n <= 0 then I.Pure p else case p of I.Pure r -> return (return r) I.Request v _ -> I.closed v I.M m -> I.M $ liftM (to n) m I.Respond a f -> I.Respond a (to (n-1) . f) `to n` there is `view (splitAt n)` which would presumably be a little better, when used by itself, if it were written without `next`. -- 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 haskell-pipes+unsubscr...@googlegroups.com. To post to this group, send email to haskell-pipes@googlegroups.com.