Instead of carrying this state boolean around explicitly, we can use a monad to carry it implicitly.
See Control.Monad.State documentation (in GHC, but not in Hugs) http://www.haskell.org/ghc/docs/latest/html/base/Control.Monad.State.html