A really simple question: I want to implement the multiplication of 2 integers in Haskell. What I wrote doesn't compile:
mult :: Int -> Int -> Int
mult x 1 = x
mult 1 y = y
mult x y = x + (mult x-1 y)
The problem is the last statement. I've tried writing it as:
mult x y = x + (mult x-1 y)
and also
mult x y = x + (mult(x-1,y))
The error I get is:
Couldn't match expected type `Int' with actual type `Int -> Int'
In the return type of a call of `mult'
I don't know why the compiler would say that mult returns an Int -> Int when it clearly returns an Int.
multto one argument, like thismult 5, you get something of typeInt -> Intbecause you have partially applied it to one argument. Plainly, you havemult 5 :: Int -> Int. This is pretty unrelated to the issue you're having now, but I thought it might be a useful side note for the future, if not for now. If it is confusing now, ignore this until later and don't worry about it.