作为学习Haskell,Conduit和Monads的一个练习,我想创建一个输入值并将其传递的管道。在Haskell中使用Writer monad和Conduit
代码非常简单,但我发现了仍在神秘的对我来说编译错误:
log =
await >>= \case
Nothing -> return()
Just value -> do
tell [value]
yield value
runWriter $ CL.sourceList ["a", "b"] $= log $$ CL.consume
和错误:
No instance for (MonadWriter [o0] m0) arising from a use of ‘tell’
The type variables ‘m0’, ‘o0’ are ambiguous
Relevant bindings include
value :: o0
(bound at /home/vagrant/workspace/dup/app/Main.hs:241:10)
logg :: ConduitM o0 o0 m0()
(bound at /home/vagrant/workspace/dup/app/Main.hs:238:1)
Note: there are several potential instances:
instance MonadWriter w m => MonadWriter w (ConduitM i o m)
-- Defined in ‘conduit-1.2.6.4:Data.Conduit.Internal.Conduit’
instance MonadWriter w m =>
MonadWriter
w (conduit-1.2.6.4:Data.Conduit.Internal.Pipe.Pipe l i o u m)
-- Defined in ‘conduit-1.2.6.4:Data.Conduit.Internal.Pipe’
instance [safe] MonadWriter w m =>
MonadWriter w (Control.Monad.Trans.Resource.Internal.ResourceT m)
-- Defined in ‘Control.Monad.Trans.Resource.Internal’
...plus 11 others
In a stmt of a 'do' block: tell [value]
In the expression:
do { tell [value];
yield value }
In a case alternative:
Just value
-> do { tell [value];
yield value }
这种类型的检查我http://lpaste.net/169714这可能是一些关于进口? – Michael
说明,你可能打算为'log'管继续它击中的第一个项目后的方式。因为只有一件物品可以通过。所以,你应该循环递归,或者使用'awaitForever'等。 – Michael