Re: [haskell-pipes] Stateful consumers and results

瀏覽次數:25 次
跳到第一則未讀訊息

John Wiegley

未讀,
2015年8月11日 上午11:05:192015/8/11
收件者:haskel...@googlegroups.com
>>>>> Alexey Raga <alexe...@gmail.com> writes:

> I have a stateful consumer, let's say a counter:

> counter :: (Show a) => Consumer a (StateT Integer IO) ()
> counter = do
> x <- await
> lift $ S.modify (+1)
> liftIO $ print $ show x
> counter

> But how do I get the final state from it?

main :: IO ()
main = do
x <- flip S.execStateT 0 $ runEffect $ each [1,2,3,4,5,6] >-> counter
print x

John
回覆所有人
回覆作者
轉寄
0 則新訊息