【发布时间】:2011-12-22 18:49:08
【问题描述】:
上下文:我正在尝试生成一个错误 monad,它还跟踪警告列表,如下所示:
data Dangerous a = forall e w. (Error e, Show e, Show w) =>
Dangerous (ErrorT e (State [w]) a)
即Dangerous a 是导致 (Either e a, [w]) 的操作,其中 e 是可显示的错误,w 是可显示的。
问题是,我似乎无法真正运行它,主要是因为我不太了解存在类型。观察:
runDangerous :: forall a e w. (Error e, Show e, Show w) =>
Dangerous a -> (Either e a, [w])
runDangerous (Dangerous f) = runState (runErrorT f) []
这不会编译,因为:
Could not deduce (w1 ~ w)
from the context (Error e, Show e, Show w)
...
`w1' is a rigidtype variable bound by
a pattern with constructor
Dangerous :: forall a e w.
(Error e, Show e, Show w) =>
ErrorT e (State [w]) a -> Dangerous a
...
`w' is a rigid type variable bound by
the type signature for
runDangerous :: (Error e, Show e, Show w) =>
Dangerous a -> (Either e a, [w])
我迷路了。 w1是什么?为什么我们不能推断它是~ w?
【问题讨论】:
标签: haskell monads monad-transformers existential-type