the standard amortized constant time queue example, in the state monad