The solution Michael gave is almost correct. It calls the monadic action
after the `await` but the code Pierre linked to calls the monadic action
before the `await`.
The concise way to put the monadic action before the `await` is to use
`(>~)` instead:
execU m = (lift m >> await) >~ cat
That replaces every `await` in `cat` with `(lift m >~ await)`, which has
the desired effect.
On Mar 6, 2014 5:43 PM, "Michael Thompson" <[email protected]>
wrote:
> I'll attempt an answer so Gabriel can test our comprehension together ...
> but I think the preferred definition would be
>
> execU ma = for cat (\a -> lift ma >> yield a)
>
> or, since `Pipes.Prelude.mapM` is defined in terms of `for cat` , just
>
> execU ma = P.mapM (<$ ma)
>
> the idea being that with rewrite rules `>-> for cat blah` can be fused
> with the previous pipe. (I take it the point is to avoid a second pile of
> recursion as with `forever`)
>
> Near the top, the docs for Pipes.Prelude
> http://hackage.haskell.org/package/pipes-4.1.0/docs/Pipes-Prelude.html say
>
> Use for loops to iterate over Producers whenever you want to
> perform the same action for every element:
> ...
> runEffect $ for P.stdinLn (lift . putStrLn)
>
> `execU` wasn't supposed act directly on a Producer, but to make a Pipe;
> but I think you can get away with this by using `for cat ...` given the
> many rewrite rules devoted to this point.
>
> There's some discussion of it here
> https://groups.google.com/d/msg/haskell-pipes/hyaUTNRXD9A/WJwybxJOyMwJbut I
> think it came up a few times on this list.
>
>
> --
> 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].
>
--
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].