小编Tsv*_*ski的帖子

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

使用 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 …
Run Code Online (Sandbox Code Playgroud)

haskell ghc

8
推荐指数
1
解决办法
445
查看次数

将函数依赖重用为类型函数

我有一个使用函数依赖和示例实例的类型类:

\n
class (KnownSymbol name) => MyClass name result | name -> result\n\ninstance MyClass "something" Int\n
Run Code Online (Sandbox Code Playgroud)\n

我如何重用它并获得类型级函数GetType以便GetType "something"返回Int

\n

我不成功的尝试非常天真:

\n
class CanGetType a b | a -> b where\n  type GetType a\n\ninstance (MyClass name result) => CanGetType name result where\n  type GetType name = result\n
Run Code Online (Sandbox Code Playgroud)\n

失败了:

\n
The 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\n
Run Code Online (Sandbox Code Playgroud)\n

haskell

5
推荐指数
0
解决办法
87
查看次数

标签 统计

haskell ×2

ghc ×1