Finite state machines built on the state monad