Add a `StateT` layer to each component's base monad. They will then
share that state. Here is an example:
import Control.Monad (forever)
import Control.Monad.Trans.State
import Pipes
producer :: Producer Int (StateT Int IO) r
producer = forever (do
n <- lift get
lift (put $! n + 1)
yield n )
consumer :: Consumer Int (StateT Int IO) r
consumer = forever (do
n <- await
lift (lift (print n))
lift (modify (+ 1)) )
main :: IO ()
main = evalStateT (runEffect (producer >-> consumer)) 0
That will print:
0
2
4
6
...
On 04/28/2015 09:36 PM, Ray Qiu wrote:
How to share state between pipes Consumers/Pipes without using ioref?
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 haskell-pipes+unsubscr...@googlegroups.com
<mailto:haskell-pipes+unsubscr...@googlegroups.com>.
To post to this group, send email to haskell-pipes@googlegroups.com
<mailto:haskell-pipes@googlegroups.com>.
--
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.