为什么 Glasgow Haskell 编译器会在此处报告多个类型错误?
Why does the Glasgow Haskell Compiler report multiple type errors here?
考虑以下 Haskell 代码
module TypeErrors where
f xs = [True | _ <- repeat 0]
x = (x, x)
Glasgow Haskell 编译器(版本 7.8.4)给出了三个类型错误。第二个和第三个来自第 3 行隐含的无限类型。第一个是
TypeErrors.hs:2:32:
No instance for (Num t0) arising from the literal ‘0’
The type variable ‘t0’ is ambiguous
注释掉第 3 行后,模块按预期编译。我想更好地了解 GHC 是如何创造奇迹的。所以我的问题是:
Why does GHC object to line 2 if and only if line 3 is present?
在我看来像是一个错误。我可以确认您描述的行为出现在 7.8.4 中,但不会出现在 7.10.3、8.0.2、8.2.2 或 8.4.2 中,所有这些错误都为零个或两个,而不是零个或三个。
考虑以下 Haskell 代码
module TypeErrors where
f xs = [True | _ <- repeat 0]
x = (x, x)
Glasgow Haskell 编译器(版本 7.8.4)给出了三个类型错误。第二个和第三个来自第 3 行隐含的无限类型。第一个是
TypeErrors.hs:2:32:
No instance for (Num t0) arising from the literal ‘0’
The type variable ‘t0’ is ambiguous
注释掉第 3 行后,模块按预期编译。我想更好地了解 GHC 是如何创造奇迹的。所以我的问题是:
Why does GHC object to line 2 if and only if line 3 is present?
在我看来像是一个错误。我可以确认您描述的行为出现在 7.8.4 中,但不会出现在 7.10.3、8.0.2、8.2.2 或 8.4.2 中,所有这些错误都为零个或两个,而不是零个或三个。