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

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?

Cheers

Mike Thomas.





Re: Still confused

1999-03-14 Thread Daniel Russell

>>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?

The x on the right hand side is viewed as a function whose first argument is 
div and second argument is 10. Since the specified type of foo is

Int -> [Char]

the return type of the function x must be Int.

Now since div has the type

Integral a => a -> a -> a

and 10 has the type

Num b => b

the inferred type of x is

((a -> a -> a) -> b -> Int) 

But x is the argument to foo and is supposed to have type Int.


Dan Russell
Kingston University






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





Re: Still confused (was: Re: Type casting??)

1999-03-13 Thread Felix Schroeter

Hello again!

On Thu, Mar 11, 1999 at 08:09:54PM -0500, Steve Frampton wrote:
> [...]

> 1. Can I perform multiple statements on one line?  Eg.
>foo :: Int -> [Char]
>foo 0 = []
>foo x = b = x - 5 * 3; c = b * 5; foo(x - b * c)

>(The above is just a silly example...but you catch my meaning)

There are no statements in a functional language (except that
which is called statement as a component of the do-notation).

But the answer to what you obviously mean (judging from your
example) has already been given. (let or where)

> 2. I tried playing around with the foo function I was working with
>last time, and am getting a different error now:
>foo :: Int -> [Char]
>foo 0 = []
>foo x = ['1'] ++ foo(x div 10)

> [...]

That's a small syntactic mistake. Normal identifiers like foo, div, ...
are *never* infix operators. But you can turn every function of (at
least) two curried arguments into an infix operator by either giving
it an operator name (like ==), or enclosing the identifier in
backticks (like `div`). In fact, the latter would make your function
definition correct in my eyes.

Regards, Felix.





Re: Still confused (was: Re: Type casting??)

1999-03-13 Thread Fergus Henderson

On 12-Mar-1999, Craig Dickson <[EMAIL PROTECTED]> wrote:
> Steve Frampton wrote:
> 
> >1. Can I perform multiple statements on one line?  Eg.
> >   foo :: Int -> [Char]
> >   foo 0 = []
> >   foo x = b = x - 5 * 3; c = b * 5; foo(x - b * c)
> >
> >   (The above is just a silly example...but you catch my meaning)
> 
> That would be something like:
> 
> foo x = let b = x - 5 * 3
> c = b * 5
> in foo (x - b * c)

You can write that on one line as

foo x = let { b = x - 5 * 3; c = b - 5 * 3; } in c = b * 5

> or
> 
> foo x = foo (x - b * c) where
> b = x - 5 * 3
> c = b * 5

Likewise with that:

foo x = foo (x - b * c) where { b = x - 5 * 3; c = b - 5 * 3; }

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW:   |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]| -- the last words of T. S. Garp.





Re: Still confused (was: Re: Type casting??)

1999-03-13 Thread Fergus Henderson

On 11-Mar-1999, Steve Frampton <[EMAIL PROTECTED]> wrote:
> 2. I tried playing around with the foo function I was working with
>last time, and am getting a different error now:
>foo :: Int -> [Char]
>foo 0 = []
>foo x = ['1'] ++ foo(x div 10)
> 
>[You'll recall last time the last line was:  ... foo(x - 1) ]
> 
>But now I get:
> 
>*** term   : foo
>*** type   : ((a -> a -> a) -> b -> Int) -> [Char]
>*** does not match : Int -> [Char]
> 
>Huh?  I tried all manner of things, like ((x::Int) div 10),
>((x div 10)::Int), etc. to no avail.

You need to write "x `div` 10" rather than "x div 10".

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW:   |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]| -- the last words of T. S. Garp.





Re: Still confused

1999-03-12 Thread Tomasz Łukaszewicz

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]
>   Huh?  I tried all manner of things, like ((x::Int) div 10),
>   ((x div 10)::Int), etc. to no avail.


   "div" is a prefix operator. When you write "x div ..." the compiler
treats "x" as function which takes an argument "div".
So instead of "x div 10" you should write "div x 10" (or alternatively
"x `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 (was: Re: Type casting??)

1999-03-12 Thread Nick Kallen

> 2. I tried playing around with the foo function I was working with
>last time, and am getting a different error now:
>foo :: Int -> [Char]
>foo 0 = []
>foo x = ['1'] ++ foo(x div 10)

You should have typed "9 div 3" at the listener and you'd have figured out
your error. No infix operators in haskell are just plane words. The
convention is to add the obtuse accent mark around identifiers, a la:

9 `div` 3
foo `bind` bar

If you remove the accent marks, you have a non-infix operator, so while 9
div 3 is invalid, div 9 3 is not.