Files
advanced-pattern-matching-c…/samples/fpsamples/sample3.hs
T
2022-07-22 15:00:53 +01:00

12 lines
334 B
Haskell

-- This function uses a boolean guard and defines
-- its value only for the remaining cases.
fact :: Int -> Int
fact x | x <= 1 = 1
| otherwise = x * (fact (x - 1))
-- Alternatively, pattern matching can be used for an
-- even more explicit declaration.
fact' :: Int -> Int
fact' 0 = 1
fact' 1 = 1
fact' x = x * (fact (x - 1))