Opened 4 years ago

Closed 4 years ago

#7791 closed bug (invalid)

Bad error message when strictness annotations are used without BangPatterns pragma

Reported by: manzyuk Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.4.1
Keywords: Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: Incorrect warning at compile-time Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Loading the program

powers n = go 1 where
  go !k = k : go (k * n)

into GHCi results in an error:

*Main> :load "/home/manzyuk/tmp/example.hs"
[1 of 1] Compiling Main             ( /home/manzyuk/tmp/example.hs, interpreted )

/home/manzyuk/tmp/example.hs:1:12: Not in scope: `go'
Failed, modules loaded: none.

The error message is plain wrong. The problem is fixed by enabling BangPatterns pragma. It would be nice if GHC could suggest that like it does in many other similar cases.

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.4.1
$ uname -a
Linux paddy 2.6.32-45-generic #104-Ubuntu SMP Tue Feb 19 21:20:09 UTC 2013 x86_64 GNU/Linux

Change History (3)

comment:1 Changed 4 years ago by monoidal

The error message is correct, since without extensions, the declaration go ! k = ... defines an operator called ! (analogously to go * k = ...) and therefore go is out of scope in line 1. You can get a nice suggestion if you write go (!k) = ... or go !k !l = .... It's hard to expect GHC to deduce from context whether a syntactically-correct go ! k = ... was meant to be something different.

comment:2 Changed 4 years ago by manzyuk

Thanks for the clarification, this makes sense. I guessed I assumed go !k and go ! k were parsed differently. I'm not convinced that GHC can't detect this situation, but it's probably a corner case that is not worth the added complexity. Please feel free to resolve the ticket.

comment:3 Changed 4 years ago by simonpj

difficulty: Unknown
Resolution: invalid
Status: newclosed

Yes, the trouble is that

go !k = go + k

really is a valid definition in Haskell 98, and there is not much we can do about that.


Note: See TracTickets for help on using tickets.