I am using GHCI 7.10.3 and I'm getting error in a simple fatorial code.
I would like to do something like this:
fatorial n
| n == 0 = 1
| n > 0 = n * fatorial(n-1)
| otherwise = error "My error"
But when fatorial -4
was called, the output was:
:21:1: Non type-variable argument in the constraint: Num (a -> a) (Use FlexibleContexts to permit this) When checking that ‘it’ has the inferred type it :: forall a. (Num a, Num (a -> a), Ord a) => a -> a
My code works fine without the last line. So how can I use error message in haskell?
factorial - 4
(so a subtraction), you should usefactorial (-4)
. – Willem Van Onsem