Haskell:存在类型的记录更新

Haskell:存在类型的记录更新,haskell,record,existential-type,Haskell,Record,Existential Type,当我遇到错误时,我正试图对存在记录使用记录更新。一个快速的google让我找到了它,它显示它在版本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 =

当我遇到错误时,我正试图对存在记录使用记录更新。一个快速的google让我找到了它,它显示它在版本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 } 
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}
产生与功能请求中投诉的错误相同的错误:

{-# 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}

这是某个时候有意放弃的功能,还是我应该提交一份错误报告?

事实上,Trac slip说它是在版本6.12中实现的-错误是在版本6.8.3中发现的。因此,您使用的版本比修复版本旧


此外,修复的changelog条目似乎表明它还没有完全修复;您仍然会遇到第一个错误,而不是第二个错误。如果对于问题的其余部分还没有bug报告,我会说继续并归档。

还有另一种方法


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

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


,则编译时不会出错。-使用ghc-6.12.2.20100531

Ah。谢谢你让我避免犯愚蠢的错误,因为你认为应该在我的版本中修复它。出发去更新GHC!啊,新的和不同的错误消息,就像你说的。但是一个认为我做错了什么的人,不是说这是不可能的。