我正在尝试理解来自http://www.yesodweb.com/book/conduits的代码。经过一些修复(比如用Resource
替换MonadResource
),它仍然无法编译:
sumSink :: MonadResource m => Sink Int m Int
sumSink = CL.fold (+) 0
sum' :: [Int] -> Int
sum' input = runST $ runResourceT $ CL.sourceList input $$ sumSink
给了我以下错误:
Couldn't match type `GHC.ST.ST s' with `IO'
When using functional dependencies to combine
Control.Monad.Trans.Control.MonadBaseControl
(GHC.ST.ST s) (GHC.ST.ST s),
arising from the dependency `m -> b'
in the instance declaration in `Control.Monad.Trans.Control'
Control.Monad.Trans.Control.MonadBaseControl IO (GHC.ST.ST s),
arising from a use of `runResourceT'
at D:\Works\stablename\test.hs:43:22-33
In the expression: runResourceT
In the second argument of `($)', namely
`runResourceT $ CL.sourceList input $$ sumSink'
我正在使用GHC 7.4.1和conduit-0.4.2。
P.S。是否有任何教程没有打破/用pipe-0.4编写?
答案 0 :(得分:1)
回答我自己的问题:
Monad m
代替Resource m
。runResourceT
之类的函数在链中某处使用,则需要应用sinkFile
,因为sinkFile
需要MonadResource m
并且MonadResource IO
没有实例}。