I’m trying to get this piece of haskell code to work, however I keep getting this error message:
> ERROR file:.\4.hs:9 - Type error in application
> Expression : fact n div (fact m * fact (n - m))
> Term : fact
> Type : Int -> Int
> Does not match : a -> b -> c -> d
Here’s the code:
fact :: Int -> Int
fact q
| q == 1 = 1
| otherwise = q * fact(q-1)
comb :: Int -> Int -> Int
comb n m
| n < m = error "undefined as n < m"
| otherwise = ((fact n) div ((fact m) * (fact (n - m))))
Any idea how to fix it?
The problem is
divin the last line.When you want to make a function infix, you have to write it between `. So, simply change the last line to: