I. Pure Versus Impure

A purely functional program can be seen as a mathematical function. The definition of this function explains how to evaluate one expression. The explanation may involve the evaluation of other functions. Each explanation has referential transparency which means that if you see the same expression twice within one context the thing it represents will be the same.

This contrasts with the more common imperative programming paradigm. Imperative programs are a sequence of commands. Some of these commands change the values assigned to variables and perform other side effects so that referential transparency is lacking.

As an example of referential transparency consider this definition of a factorial function

f 0 = 1
f x = x * (f (x-1))

To evaluate f 3, x has the fixed meaning of 3. It doesn't alter this value during the evaluation of f 3. Instead time out is taken to evaluate f 2. During that evaluation x has a fixed meaning of 2. Each evaluation of f is a separate context.