Reputation: 1437
I want to write a Haskell program that calculates the sum of numbers between 2 given numbers. I have the following code:
sumInt :: Int -> Int -> Int
sumInt x y
| x > y = 0
| otherwise = x + sumInt x+1 y
But when I compile it I get the following error:
SumInt is applied to too few arguments.
I don't understand what I'm doing wrong. Any ideas?
Upvotes: 6
Views: 6627
Reputation: 54058
You need parentheses around x+1
:
| otherwise = x + sumInt (x + 1) y
The reason is that function application binds more tightly than operators, so whenever you see
f x <> y
This is always parsed as
(f x) <> y
and never as
f (x <> y)
Upvotes: 7