尝试在 Haskell 中使用存在类型时出现编译错误

发布于 2025-01-05 17:27:20 字数 910 浏览 2 评论 0原文

我收到如下错误消息:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖树树初阳… 2025-01-12 17:27:20

我有一个猜测,但在您发布足够的代码来重现错误之前我无法确定。我的猜测是基于查看这个:

runSubstT :: (Monad m) =>; (forall v.(Ident v) => SubstT vamb) ->米·b

是使第二类型“a”依赖于第一个存在类型“v”可能是一个问题。预期类型:

forall v1。识别 v1 => SubstT v1 (GenericLL (a v1 c)) n x'

将第二类型替换为 (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:

runSubstT :: (Monad m) => (forall v. (Ident v) => SubstT v a m b) -> m b

is that making the second type 'a' dependent on the first existential type 'v' may be a problem. The expected type:

forall v1. Ident v1 => SubstT v1 (GenericLL (a v1 c)) n x'

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文