我试图对一个存在记录使用记录更新时遇到了一个错误。用谷歌快速搜索一下,我找到了feature request #2595,上面显示它在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}这是在某个时候故意放弃的功能,还是我应该提交错误报告?
发布于 2011-01-03 05:00:19
实际上,Trac slip说它是在6.12版本中实现的--这个bug是在6.8.3版本中发现的。因此,您使用的版本比修复版本旧。
此外,修复的changelog条目似乎表明它没有完全修复;您仍然会收到第一个错误,但不是第二个错误。如果问题的其余部分还没有bug报告,我会说继续并提交。
发布于 2011-01-21 22:26:36
还有另一种方法!
如果将数据类型定义从
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
https://stackoverflow.com/questions/4580211
复制相似问题