尝试在 Haskell 中使用存在类型时出现编译错误
我收到如下错误消息:
Linear.hs:215:27:
Couldn't match expected type `forall v1.
Ident v1 =>
SubstT v1 (GenericLL (a v1 c)) n x'
with actual type `forall v1. Ident v1 => SubstT v1 a0 m0 b0'
Expected type: (forall v1.
Ident v1 =>
SubstT v1 (GenericLL (a v1 c)) n x)
-> n x
Actual type: (forall v1. Ident v1 => SubstT v1 a0 m0 b0) -> m0 b0
In the first argument of `flattenImpl', namely `runSubstT'
In the expression: flattenImpl runSubstT
实际类型似乎比预期类型更通用。那么出现这种错误信息的可能原因有哪些呢?该消息是否具有误导性或者我读错了?
我想做的是传递一个存在量化函数 runSubstT
,其类型为:
runSubstT :: (Monad m) => (forall v. (Ident v) => SubstT v a m b) -> m b
我还将对 GHC 编译器如何对存在量化类型执行类型匹配进行一些很好的描述。
I am getting an error message like so:
Linear.hs:215:27:
Couldn't match expected type `forall v1.
Ident v1 =>
SubstT v1 (GenericLL (a v1 c)) n x'
with actual type `forall v1. Ident v1 => SubstT v1 a0 m0 b0'
Expected type: (forall v1.
Ident v1 =>
SubstT v1 (GenericLL (a v1 c)) n x)
-> n x
Actual type: (forall v1. Ident v1 => SubstT v1 a0 m0 b0) -> m0 b0
In the first argument of `flattenImpl', namely `runSubstT'
In the expression: flattenImpl runSubstT
The actual type seems more general than the expected type. What are then possible causes for this kind of error message? Is the message misleading or am I reading it incorrectly?
What I am trying to do is to pass an existentially quantified function runSubstT
, whose type is:
runSubstT :: (Monad m) => (forall v. (Ident v) => SubstT v a m b) -> m b
I will also settle with some good description of how the GHC compiler performs type matching on existentially quantified types.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个猜测,但在您发布足够的代码来重现错误之前我无法确定。我的猜测是基于查看这个:
是使第二类型“a”依赖于第一个存在类型“v”可能是一个问题。预期类型:
将第二类型替换为 (GenericLL (a v1 c)),这取决于第一个存在类型 'v1'。这可能是冲突的根源,但如果没有代码,我无法跟踪类型检查器的登录。
I have a guess, but I cannot be sure until you post enough code to reproduce the error. My guess, based on looking at this:
is that making the second type 'a' dependent on the first existential type 'v' may be a problem. The expected type:
replaces the second type with (GenericLL (a v1 c)) which depends on the first existential type 'v1'. This could be the root of the conflict, but without the code I cannot trace the login of the type checker.