haskell - Parse error on guards -


factorial :: int -> int   factorial 0 = 1  factorial n     | n < 0 == error "cant call nagative number"    | otherwise = n * factorial (n-1) 

can explain why getting error?

haskell.hs:77:2: parse error on input ‘|’ 

you need use = not == in function definition:

factorial :: int -> int  factorial 0 = 1 factorial n     | n < 0     = error "cant call nagative number"    | otherwise = n * factorial (n-1) 
  • = syntactic atom used defining things;
  • == function/operator used comparing values.

Comments