我正在尝试从wikibooks / Haskell的CPS章中找出the coroutines example,但是我不明白为什么runCoroutineT
函数最后需要. (<* exhaust)
,如果我更改了函数来自
runCoroutineT = flip evalStateT [] . flip runContT return . runCoroutineT' . (<* exhaust)
to
runCoroutineT = flip evalStateT [] . flip runContT return . runCoroutineT'
该示例似乎为keep working(看一下第56行)任何人都可以解释是否有错误吗?
在我看来,它不起作用。您链接到的示例程序以[]结尾
example = runCoroutineT $ do fork $ replicateM_ 3 (printOne 3) fork $ replicateM_ 4 (printOne 4) replicateM_ 2 (printOne 2)
但是运行时,不是所有的4都打印出来:
3 4 3 2 4 3 2 4
应该有四个!
exhaust
的要点是结束所有等待运行的线程,而如果没有它,则可能无法完成某些线程的运行。