Haskell:存在类型的记录更新

ram*_*ion 6 haskell record existential-type

当我遇到错误时,我试图将记录更新用于存在记录.一个快速谷歌引导我提出功能请求#2595,它显示它是在版本6.8.3中为GHC实现的.我正在使用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 } 
Run Code Online (Sandbox Code Playgroud)

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

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}
Run Code Online (Sandbox Code Playgroud)

这是一个有意识的删除功能,或者我应该提交错误报告?

Luk*_*rer 5

实际上,Trac单据表示它是在6.12版本中实现的 - 该漏洞是在6.8.3版本中找到的.因此,您使用的版本比修复程序早.

此外,修复程序的更改日志条目似乎表明它没有完全修复; 你仍然会得到第一个错误,而不是第二个错误.如果还没有针对问题的其余部分的错误报告,我会说继续并提交.

  • 啊.感谢您通过假设我应该修复我的版本来避免犯下愚蠢的错误.关闭去更新GHC! (2认同)