使用 GHC 8.10 和 9.0foo (a :: Aaa)
足以消除我要使用的字段的歧义。\n自 9.2 起,我现在收到警告(模糊字段):
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
外部库,来自同一模块:
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)\nfunc2
是唯一无警告的解决方案。这真的是目前最好的方法吗?\n完全忽略了案例分析(这和不编译func3
是一样的)。foo a
我正在使用 9.2.3。
\n小智 1
我也遇到过和你类似的情况,最后发现OverloadedRecordDot
可以这样做。
{-# LANGUAGE OverloadedRecordDot #-}
func4 :: Int
func4 = a.foo
Run Code Online (Sandbox Code Playgroud)