Re: Still confused

1999-03-14 Thread Tomasz ukaszewicz

Mike Thomas [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?

   In fact "div" is not used incorrectly in the above example; expression
"x div 10" is correct when considered apart from the rest of the program.
Error comes from the fact that foo was declared as "Int - Char" and
in definition "foo x = foo (x div 10)" foo can't have this type.

I'm afraid that my mind doesn't immediately jump to the conclusion that div
without quotes is not an infix operator when I see the error message.
Surely minor syntactical errors can be reported in a more meaningful manner?

   As I've written "x div 10" it's not syntactical error. We can write:

x :: (Int - Int - Int) - Int - Int
x function argument = function 42 argument

   and then

x div 10

is correct expression of type Int (equal to 42 `div` 10).

-- 
Tomasz Lukaszewicz  o   ___|   "I have no idea
mailto:[EMAIL PROTECTED]   o /o  \/| |   what to write here."
http://www.tomasz.w.pl/english/\___/\| | -- Me --





RE: Still confused

1999-03-14 Thread chris angus


 
 Hi all.
 
 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?
 
 I'm afraid that my mind doesn't immediately jump to the 
 conclusion that div
 without quotes is not an infix operator when I see the error message.
 
 Surely minor syntactical errors can be reported in a more 
 meaningful manner?

The whole problem is that is is not a syntax error.
The syntax is valid. It's a tying error. Admitedly a confusing one.


 
 Cheers
 
 Mike Thomas.
 





Re: Still confused

1999-03-14 Thread Scott Turner

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