Reputation: 31
newcomer to Haskell here.
I have this function:
addNums num1 num2 =
num1 + num2
when I try to run addNums 1 -2
with GHCi, it returns this error:
<interactive>:40:1: error:
* No instance for (Show (Integer -> Integer))
arising from a use of `print'
(maybe you haven't applied a function to enough arguments?)
* In a stmt of an interactive GHCi command: print it
I notice that in order for it to run as intended, I need to add parentheses: addNums 1 (-2)
. Why is that?
Upvotes: 1
Views: 396
Reputation: 80754
The code you wrote is being parsed as (addNums 1) - 2
, so the compiler takes the result of addNums 1
, which is a function Integer -> Integer
, and tries to subtract 2
from it.
For correct passing order, you need to add parentheses around the second parameter:
addNum 1 (-2)
Upvotes: 3