Nit: File Parsing Error Messages

Under the Cygwin build, a poorly-indented source file: -- -- Note indention at line #8 -- module Main where import IO add :: Integer -> Integer -> Integer add x y = x + y inc = add 1 -- ^^^ Indented two spaces main = do putStrLn ("Hello, World.") -- -- End program -- This results in the somewhat confusing error message: $ hmake test nhc98 -c -o test.o test.hs In file ./test.hs: 8:9 Found = but expected a {-EOF-} It might be better if it indicated the indentation was at issue. Correcting the indentation results in a successful compile. I have not verified this on a "real" system (Linux/BSD/etc.), so it's possible it's limited to Cygwin's environment. Thanks, -Brent

Brent Fulgham wrote:
add :: Integer -> Integer -> Integer add x y = x + y
inc = add 1 -- ^^^ Indented two spaces
8:9 Found = but expected a {-EOF-}
This error message is independent of the operating system, you get it on any system. The error message is definitely rather terse (I guess {- EOF -} means end of file although end of function definition would be more appropriate). Nonetheless, the message makes sense: because `inc' is indented, nhc thinks that it belongs to the right hand side of the previous definition. Basically it reads it as if you had written add x y = x + y inc = add 1 Hence complaining about `=' makes sense. Producing better error messages by guessing what the programmer meant is always prone to error and may lead to even more confusion. So for example you could also have meant to write add x y = x + y where inc = add 1 This seems unlikely, because `inc' is not used on the right hand side of the definition of `add'. But what if it had been used there? However, you are certainly right in that we should try to improve nhc's error messages. Cheers, Olaf -- OLAF CHITIL, Dept. of Computer Science, University of York, York YO10 5DD, UK. URL: http://www.cs.york.ac.uk/~olaf/ Tel: +44 1904 434756; Fax: +44 1904 432767
participants (2)
-
Brent Fulgham
-
Olaf Chitil