GHC 9.2 中的不明确记录字段警告

Tsv*_*ski 8 haskell ghc

使用 GHC 8.10 和 9.0foo (a :: Aaa)足以消除我要使用的字段的歧义。\n自 9.2 起,我现在收到警告(模糊字段):

\n
    The field \xe2\x80\x98foo\xe2\x80\x99 belonging to type Aaa is ambiguous.\n    This will not be supported by -XDuplicateRecordFields in future releases of GHC.\n    You can use explicit case analysis to resolve the ambiguity.\n
Run Code Online (Sandbox Code Playgroud)\n

考虑以下代码片段,记住它Aaa来自Bbb外部库,来自同一模块

\n
    The field \xe2\x80\x98foo\xe2\x80\x99 belonging to type Aaa is ambiguous.\n    This will not be supported by -XDuplicateRecordFields in future releases of GHC.\n    You can use explicit case analysis to resolve the ambiguity.\n
Run Code Online (Sandbox Code Playgroud)\n

func2是唯一无警告的解决方案。这真的是目前最好的方法吗?\n完全忽略了案例分析(这和不编译func3是一样的)。foo a

\n

我正在使用 9.2.3。

\n

小智 1

我也遇到过和你类似的情况,最后发现OverloadedRecordDot可以这样做。

{-# LANGUAGE OverloadedRecordDot #-}

func4 :: Int
func4 = a.foo
Run Code Online (Sandbox Code Playgroud)