【发布时间】:2012-03-15 18:34:23
【问题描述】:
我需要使用列表单子转换器。我从Control.Monad.List 了解到ListT IO 存在潜在问题,因为IO 不是可交换的,所以我正在查看ListT done right。但我遇到了一些意想不到的行为。
考虑这个简单的测试:
test = runListT $ do
x <- liftList [1..3]
liftIO $ print x
y <- liftList [6..8]
liftIO $ print (x,y)
使用 Control.Monad.List:
Main> test
1
(1,6)
(1,7)
(1,8)
2
(2,6)
(2,7)
(2,8)
3
(3,6)
(3,7)
(3,8)
[(),(),(),(),(),(),(),(),()]
使用“ListT 做得对”:
Main> test
1
(1,6)
这是“ListT 做得对”的问题,还是我只是用错了?有没有首选的替代方案?
谢谢!
【问题讨论】:
标签: haskell monads generic-list monad-transformers