At 16:23 1999-03-14 +1000, Mike Thomas <[EMAIL PROTECTED]> wrote:
>>Steve Frampton <[EMAIL PROTECTED]> wrote:
>>>   foo x = ['1'] ++ foo(x div 10)
>>>   *** term           : foo
>>>   *** type           : ((a -> a -> a) -> b -> Int) -> [Char]
>>>   *** does not match : Int -> [Char]
>
>
>Can someone please explain how to decipher the type line in this error
>message in such a way that we come to div being used incorrectly?

>Surely minor syntactical errors can be reported in a more meaningful manner?

That depends.  There may be several different minor syntactical errors that
all yield the same erroneous program.  The compiler's message will appear
meaningful only if it corresponds to the particular error which the
programmer made.

At the level of syntax, the compiler's primary business is to recognize a
correct program, and explain what is erroneous about an incorrect program.
That can be quite different from figuring out what the programmer's error was.

In this case, your error was to type div rather than `div`.  But leaving
off the back-quotes is not an error in itself.  In fact, 
          foo x = ['1'] ++ bar(x div 10)
    and   foo x = ['1'] ++ (x div 10)
are both valid.  Thus, to provide a "meaningful" error message is a matter
of tailoring the compiler to recognize the results of common pitfalls.
Even with such enhancements, an compiler can't tell for sure what the error
was.  The best diagnostic message you can hope for might be (and I've
actually seen this approach used):
      foo x = ['1'] ++ foo(x div 10)
      *** term           : foo
      *** type           : ((a -> a -> a) -> b -> Int) -> [Char]
      *** does not match : Int -> [Char]
      *** Perhaps you intended `div` rather than div.

(This message to the Haskell list is based on my experience as a compiler
writer, not with Hugs.)

--
Scott Turner
[EMAIL PROTECTED]       http://www.ma.ultranet.com/~pkturner


Reply via email to