我一直在尝试编写函数的实现:
foo :: Monad m => ConduitM i o (forall s. STT s m) r -> ConduitM i o m r但我在每一个错误中都失败了:
Couldn't match type because variable `s` would escape its scope.我现在怀疑实现这个函数是不可能的。
threadSTT :: Monad m
=> (forall a. (forall s. STT s m a) -> m a)
-> ConduitM i o (forall s. STT s m) r
-> ConduitM i o m r
threadSTT runM (ConduitM c0) =
ConduitM $ \rest ->
let go (Done r) = rest r
go (PipeM mp) = PipeM $ do
r <- runM mp -- ERROR
return $ go r
go (Leftover p i) = Leftover (go p) i
go (NeedInput x y) = NeedInput (go . x) (go . y)
go (HaveOutput p f o) = HaveOutput (go p) (runM f) o -- ERROR
in go (c0 Done)
foo :: Monad m => ConduitM i o (forall s. STT s m) r -> ConduitM i o m r
foo = threadSTT STT.runST有人能对此说话吗?我真的很喜欢它的工作,但如果我不能,那么我需要放弃使用Data.Array.ST来编写我的管道。
发布于 2016-02-07 08:41:58
似乎您已经重新发明了MFunctor实例ConduitM。你可以检查一下源代码。
作者的管道包,这种风格的monad提升机当你试图打开带有副作用的单片时,会产生令人惊讶的效果。。在这种情况下,runST将被多次调用,因此每次管道生成项时都会抛出状态。
您最好将线路上的所有其他管道从Conduit i o m r提升到Conduit i o (STT s m) r,并根据结果调用runST。这和transPipe lift一样简单。
https://stackoverflow.com/questions/35249381
复制相似问题