Haskell - too few arguments

I want to write a Haskell program that calculates the sum of numbers between two 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 applies to arguments that are too small.

I don't understand what I am doing wrong. Any ideas?

+3


source to share


1 answer


You need parentheses around x+1

:

| otherwise = x + sumInt (x + 1) y

      

The reason is that function app binds more rigidly than operators, so whenever you see

f x <> y

      



This is always parsed as

(f x) <> y

      

and never will

f (x <> y)

      

+5


source







All Articles