I believe Haskell is interpreting the input as (abs - 5) which is not valid for abs. '-' is an operator and abs expects one parameter of type t

Prelude> :t abs
abs :: t -> t

Prelude> :t abs - 5
abs - 5 :: (t -> t) -> t -> t

If you enter abs (-5) you will get the correct answer.

Gregg

On 5/12/2012 4:15 PM, Ashley Smith wrote:
I was wondering if someone could explain this error? I typed in the sample code from the Haskell Beginning Wikibook to define a function for absolute value. I have GHC 7.0.4 for OSX. The error went away when I put parentheses around the negative value, so did the Haskell interpreter think I was entering - and a second argument, namely 10, when the parentheses weren't there? Thank you!

*Main> let abs x = if x < 0 then -x else x
*Main> abs 5
5
*Main> abs -10

And got the following error
<interactive>:1:6:
    No instance for (Num (a0 -> a0))
      arising from the literal `10'
    Possible fix: add an instance declaration for (Num (a0 -> a0))
    In the second argument of `(-)', namely `10'
    In the expression: abs - 10
    In an equation for `it': it = abs - 10




_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners