Chapter 6. On Pattern Matching

Pattern matching is a concept which, as far as I know, is unique to functional programming languages. This is not regular expression pattern matching that you find in languages like perl. Pattern matching is a means of selecting the function you want based on the form of its type.

6.1. Factorial Example

Looks very declarative, doesn't it?

fact :: Integer -> Integer
fact 0 = 1
fact n
    | n < 0 = error "Don't know how to do negative factorial."
    | otherwise = n * (fact (n - 1))