They are equivalent even without the rewrite rules. This is something I
really want to emphasize: even if you turn off all rewrite rules they
both evaluate to the exact same pipe:
(lift m >> await) >~ cat = go
where go = M (m >> return (Request () (\a -> Respond a(\() -> go))))
forever (await >>= yield) = go
where go = M (m >> return (Request () (\a -> Respond a (\() -> go))))
The rewrite rules do not change the final pipe that you get: the only
thing they do is help `ghc` compute the final pipe faster.
To answer your second question, `execU` can be rewritten for fusion:
execU >-> p = (lift m >> await) >~ p
However, if the `mapM` form is acceptable then you should prefer it,
because more pipes can implement for loop fusion than feed loop fusion,
and if you consistently use either all for loop fusion or all feed loop
fusion you get better overall fusion for the entire pipeline.
To answer your third question, you usually need `INLINABLE` to get the
rewrite rules to fire.
On 3/7/2014 3:43 AM, Pierre R wrote:
I need to check my understanding ...
1) both implementations
execU m = (lift m >> await) >~ cat
and the original one:
execU mOp = forever $ do
lift mOp
await >>= yield
are equivalent given the rewrite rules (at least with latest versions
of ghc that had the implementation of `forever` fixed)
2) Let's say the order doesn't matter (as it might be the case in the
linked code). Is it then better to use `mapM` to get the monadic
action of `execU` fused with the upstream producer ?
3) Is it necessary to add `INLINABLE` for `execU` to get the rewrite
rules to fire.
Thanks.
--
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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
--
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].