Lazy evaluation, functional code, and persistent data structures are nice and all, but they are not meant to wholly replace imperative strict evaluation, imperative code, and ephemeral structures. Nor vice versa. Instead, all complement each other. Although the default evaluation in Haskell is strict and a functional style is strongly encouraged, Haskell is more than capable of providing for programming in imperative style:
"In short, Haskell is the world's finest imperative programming language." | ||
--Simon Peyton Jones (in his paper Tackling the Awkward Squad) |
Imperative programming calls for sequential processing. In Haskell, we tackle sequential steps with monads. The monad of choice for ephemeral data structures is IO or ST. ST (for state threads) behaves a bit more nicely than IO in that you cannot launch missiles from ST. An ST action can be executed in pure code, or converted to an IO action:
import Control.Monad.ST runST :: (forall s. ST s a) -> a stToIO...