Open kvanbere opened 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.
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.
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 offor
, which tells pipes automatic general fusion is safe, thus doing all the work for us.