Hugs 1.4 produces some error messages which are hard to understand but, I
believe, could be easily improved. Maybe you can make Hugs 98 produce better
ones.

The following two error messages always baffle students. They think they
discovered a bug in Hugs (people are used to buggy software ;-)

1. The script

f x = x +
1

leads to

ERROR "Test.hs" (line 4): Syntax error in expression (unexpected `;')

And no `;' anywhere... ;-)
Well, I know that to parse the offside-rule with yacc the lexer inserts `;' and
braces where they are missing. However, couldn't the lexer insert some other
token which is treated by the parser like `;' but would give a different error
message?


2. The script

filter2 :: Eq a => a -> [(a,b)] -> [b]
filter2 x ys = foldr f [] ys
  where
  f :: (a,b) -> [b] -> [b]
  f (k,e) ys | k==x      = e:ys
             | otherwise = ys 

leads to

ERROR "Test.hs" (line 7): Declared type too general
*** Expression    : f
*** Declared type : (a,b) -> [b] -> [b]
*** Inferred type : (_11,a) -> [a] -> [a]

The `_11' is irritating. How about

*** Inferred type : (_b,a) -> [a] -> [a]
Type variables starting with `_' are quantified outside the scope of the
expression.

I don't talk about the scopes of type variables in my Haskell course. However,
such an error message would make clear that there is not bug (`_11'), but some
deeper reason related to the type system that the programmer may not know about.
He should ask his supervisor or look for literature about type variable
quantification.


3. The following error message is rather hard to understand, but probably more
difficult to improve.

Prelude> do s <- readFile; return (head s)
ERROR: Type error in application
*** expression     : head s
*** term           : s
*** type           : IO String
*** does not match : [a]

I wonder if the type checker could check earlier, if the type of `readFile' is
acually a monad. An error message like

ERROR: (FilePath->) is not an instance of class "Monad"
*** expression  : s <- readFile
*** term        : readFile
*** type        : FilePath -> IO String

would be more helpful.


4. Finally, there are all the many type errors due to the monomorphic
restriction. Maybe the error message could at least state that the MR-rule was
used during inference of the faulty type. The words `monomorphic restriction'
appearing in the error message could give at least a hint that the type problem
may be due to the MR.

Cheers,
Olaf

-- 
OLAF CHITIL, Lehrstuhl fuer Informatik II, RWTH Aachen, 52056 Aachen, Germany
             Tel: (+49/0)241/80-21212; Fax: (+49/0)241/8888-217
             URL: http://www-i2.informatik.rwth-aachen.de/~chitil/

Reply via email to