# Factorial in Haskell

Example for versions
GHC 6.10.4

This example uses the Prelude function `product`

, which computes the product of a list of numbers. When the list is empty, it returns 1 (the multiplicative identity), so this works for 0 too.

```
module Main where
factorial :: Integer -> Integer
factorial n = product [1..n]
line x = putStrLn $ show x ++ "! = " ++ factorial x
main = mapM_ line [0..16]
```

## Comments

]]>blog comments powered by Disqus

]]>