Haskell:存在类型的记录更新

发布于 2024-10-10 00:59:14 字数 1007 浏览 5 评论 0原文

当我遇到错误时,我试图对现有记录使用记录更新。快速谷歌搜索后,我找到了功能请求#2595,它显示了它的实现GHC 回到版本 6.8.3。我正在使用 6.10.4,所以我认为它应该可以工作,但是功能请求中的示例代码:

{-# LANGUAGE ExistentialQuantification,Rank2Types #-}
module Foo where

data Foo = forall a . Foo { foo :: a -> a, bar :: Int }

x :: Foo 
x = Foo { foo = id, bar = 3 } 

f :: Foo -> Foo 
f rec = rec { foo = id }

g :: Foo -> Foo 
g rec = rec { bar = 3 } 

产生与功能请求中抱怨的相同的错误:

test.hs:10:8:
    Record update for the non-Haskell-98 data type `Foo' is not (yet) supported
    Use pattern-matching instead
    In the expression: rec {foo = id}
    In the definition of `f': f rec = rec {foo = id}

test.hs:13:8:
    Record update for the non-Haskell-98 data type `Foo' is not (yet) supported
    Use pattern-matching instead
    In the expression: rec {bar = 3}
    In the definition of `g': g rec = rec {bar = 3}

这是在某个时候有意识地删除的功能,还是应该我提交错误报告?

I was trying to use record update for an existential record when I ran into an error. A quick google led me to feature request #2595, which shows it as implemented for GHC back in version 6.8.3. I'm using 6.10.4, so I'd think it should work, but the example code from the feature request:

{-# LANGUAGE ExistentialQuantification,Rank2Types #-}
module Foo where

data Foo = forall a . Foo { foo :: a -> a, bar :: Int }

x :: Foo 
x = Foo { foo = id, bar = 3 } 

f :: Foo -> Foo 
f rec = rec { foo = id }

g :: Foo -> Foo 
g rec = rec { bar = 3 } 

yield the same errors as complained of in the feature request:

test.hs:10:8:
    Record update for the non-Haskell-98 data type `Foo' is not (yet) supported
    Use pattern-matching instead
    In the expression: rec {foo = id}
    In the definition of `f': f rec = rec {foo = id}

test.hs:13:8:
    Record update for the non-Haskell-98 data type `Foo' is not (yet) supported
    Use pattern-matching instead
    In the expression: rec {bar = 3}
    In the definition of `g': g rec = rec {bar = 3}

Was this a consciously dropped feature at some point, or should I file a bug report?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

清风挽心 2024-10-17 00:59:14

实际上,Trac 单条说它是在版本 6.12 中实现的 - 该错误是在版本 6.8.3 中发现的。所以您使用的版本早于修复程序。

此外,该修复的变更日志条目似乎表明它尚未完全修复;您仍然会收到第一个错误,而不是第二个错误。如果还没有针对其余问题的错误报告,我会说继续提交。

Actually, the Trac slip says it was implemented in version 6.12 — the bug was found in version 6.8.3. So you're using a version that's older than the fix.

Also, the changelog entry for the fix seems to indicate that it's not completely fixed; you'd still be getting the first error, just not the second. If there isn't already a bug report for the rest of the problem, I'd say go ahead and file.

迷途知返 2024-10-17 00:59:14

还有一个办法!


如果将数据类型定义从 更改为

data Foo = forall a . Foo { foo :: a -> a, bar :: Int }

data Foo = Foo { foo :: forall a . a -> a, bar :: Int }

则编译不会出现错误。 --使用ghc-6.12.2.20100531

There is still another way!


If you change the data type definition from

data Foo = forall a . Foo { foo :: a -> a, bar :: Int }

to

data Foo = Foo { foo :: forall a . a -> a, bar :: Int }

, then it compiles without error. -- using ghc-6.12.2.20100531

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