k0001 / pipes-network

Use network sockets together with the Haskell pipes library.
http://hackage.haskell.org/package/pipes-network
Other
24 stars 8 forks source link

Missing pipes fusion #23

Open kvanbere opened 10 years ago

kvanbere commented 10 years ago

Lots of functions in pipes-network do not implement fusion.

Looking at the source files, it would be really clumsy (with lots of code duplication or strange naming and force inlines..) to try and implement them now, BUT I was talking with @Gabriel439 and maybe we can get a for' variant of for, which tells pipes automatic general fusion is safe, thus doing all the work for us.

Gabriella439 commented 10 years ago

To clarify what @kvanberendonck means, the for rewrite rules are guaranteed to be true if the body of the loop does not request/await, so we could provide a Pipes.Internal version of for, which type restricts the second argument, like this:

for' :: Monad m
    => Proxy x' x b' b m a'
    -> (b -> Proxy X u c' c m b')
    -> Proxy x' x c' c m a'
for' p f = p //> (closed \>\ f)

{-# RULES "for' p f" forall p f . p >-> for' cat f = for' p f #-}

I just need to make sure that fusion still fires if we use this approach because @kvanberendonck has identified some cases where pipes that are implemented in terms of fusible pipe are not triggering shortcut fusion.

k0001 commented 10 years ago

Thank for mentioning this. I admit I haven't paid incredible attention to the recent discussions about pipes fusion, but I'd be happy to make the internals of pipes-network a bit uglier if that's what we need in order to guarantee pipes fusion. However, I'd rather wait for @Gabriel439's for' and see if that makes the trick.