使用 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.\nRun 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 …Run Code Online (Sandbox Code Playgroud) 我有一个使用函数依赖和示例实例的类型类:
\nclass (KnownSymbol name) => MyClass name result | name -> result\n\ninstance MyClass "something" Int\nRun Code Online (Sandbox Code Playgroud)\n我如何重用它并获得类型级函数GetType以便GetType "something"返回Int?
我不成功的尝试非常天真:
\nclass CanGetType a b | a -> b where\n type GetType a\n\ninstance (MyClass name result) => CanGetType name result where\n type GetType name = result\nRun Code Online (Sandbox Code Playgroud)\n失败了:
\nThe RHS of an associated type declaration mentions out-of-scope variable \xe2\x80\x98a\xe2\x80\x99\n All such variables must be bound on the LHS\nRun Code Online (Sandbox Code Playgroud)\n