上下文:我正在尝试生成一个错误单子,它还跟踪警告列表,如下所示:
data Dangerous a = forall e w. (Error e, Show e, Show w) =>
Dangerous (ErrorT e (State [w]) a)
ieDangerous a
是导致(Either e a, [w])
wheree
是可显示的错误并且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
?