简体   繁体   English

为什么Glasgow Haskell编译器会在此报告多个类型错误?

[英]Why does the Glasgow Haskell Compiler report multiple type errors here?

Consider the following Haskell code 考虑以下Haskell代码

module TypeErrors where
f xs = [True | _ <- repeat 0]
x = (x, x)

The Glasgow Haskell Compiler (version 7.8.4) gives three type errors. Glasgow Haskell编译器(版本7.8.4)给出了三种类型错误。 The second and third arise from the infinite type implied by line 3. The first is 第二个和第三个来自第3行所暗示的无限类型。第一个是

TypeErrors.hs:2:32:
    No instance for (Num t0) arising from the literal ‘0’
    The type variable ‘t0’ is ambiguous

After commenting out line 3, the module compiles as expected. 注释掉第3行后,模块按预期编译。 I'd like to understand better how GHC performs its miracles. 我想更好地了解GHC如何发挥其奇迹。 So my question is: 所以我的问题是:

Why does GHC object to line 2 if and only if line 3 is present? 当且仅当第3行存在时,为什么GHC反对第2行?

Looks like a bug to me. 对我来说看起来像个错误。 I can confirm the behavior you describe appears in 7.8.4, but does not in 7.10.3, 8.0.2, 8.2.2, or 8.4.2, all of which have either zero or two errors, not zero or three. 我可以确认你描述的行为出现在7.8.4中,但不是在7.10.3,8.0.2,8.2.2或8.4.2中,所有这些都有0或2个错误,而不是0或3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM