Consider how stateful computations could be expressed in a pure functional language like Haskell. We will use a mutable stack as an example, but we'll see later that the same ideas generalize to any sort of mutable state.
A stack is a simple data structure used extensively to model imperative computation.
It is an ordered collection of values where all modifications happen at one end of the collection.
In Java, for example, a Stack
is accessed/manipulated with the following two methods: