change $ to 0 to avoid stack overflow if n is large enough

This commit is contained in:
nihonium 2023-02-12 01:03:51 +03:00
parent ae316f42fe
commit 6354df0b0c
Signed by: nihonium
GPG key ID: 0251623741027CFC

View file

@ -5,7 +5,7 @@ factorial n = if n < 0 then
Left "n cannot be negative"
else Right $ factorial' n 1 where
factorial' 0 res = res
factorial' n res = factorial' (n - 1) $ n * res
factorial' n res = factorial' (n - 1) $! n * res
main :: IO()
main = do