我一直在尝试编写该函数的实现:
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
来编写我的管道。