Haskell
fact :: Int -> Int -- fact is Int to Int
fact x = product (range x) -- fact x is product range x
range x = [1..x] -- range x is 1 to[pause] x
Haskell education time:
- The
range xfunction creates a list of integers from 1 up to the value ofx. - The
fact xfunction multiplies all the values of the listrange xtogether to compute the result. - The first line says that the
factfunction takes an integer and returns an integer.