Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Consider the following Haskell code

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

The Glasgow Haskell Compiler (version 7.8.4) gives three type errors. The second and third arise from the infinite type implied by line 3. The first is

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. I'd like to understand better how GHC performs its miracles. So my question is:

Why does GHC object to line 2 if and only if line 3 is present?

like image 951
Mark Wildon Avatar asked May 01 '18 14:05

Mark Wildon


1 Answers

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.

like image 93
Daniel Wagner Avatar answered Oct 21 '22 07:10

Daniel Wagner