Standard ML is not a pure functional language, it is a higher-order imperative language. We have already [briefly] considered exceptions and now we consider assignment and input and output. Consider the following sequence of value declarations.
val x = 0; val x = x + 1;
This resembles a sequence of assignments in an imperative program where first the variable x is given an initial value of zero and then the value of x is incremented. The final effect is, of course, that x holds the value one. On the basis of this example it might seem that changes to the environment are like changes of state. To clarify the difference between a sequence of assignments and a sequence of value declarations consider the declarations which appear below.
val x = 0; val x = x < 1; val x = if x then 1 else 0;
Once again the final effect is to leave x bound to one but in the middle of this process the identifier x was re-used to denote a boolean value. In a typed programming language which distinguishes between integers and booleans no sequence of assignments could ever achieve this effect and so we see that the value declaration mechanism brings about a re-declaration or a re-binding of the identifier x. Consider the example again.
val x = 0; val x = x < 1; val x = if x then 1 else 0;
We conclude that it is necessary to distinguish between the evironment and the state.