[Haskell-cafe] 'Proper' use of the State monad

Denis Volk denis.volk at gmail.com
Mon Apr 30 17:16:47 EDT 2007

Hello all,

I am trying to make a (turn-based) game in Haskell and need to pass
around quite a bit of information, so using the State monad seems most
appropriate. My question is, which is a better idea:

1) Using State GameState r and then call execState for each game event
(i.e. user input) so I can do IO
2) Using StateT GameState IO () and have the entire game live in one
big execStateT call. (I note XMonad does something similar.)

There are difficulties with the first option, including keeping even
more state about what we're doing (for instance, are we in a menu?),
and adding stuff later would possibly require substantial rewrites.
Other than the fact that I would have IO in places where it perhaps
shouldn't be, the second option seems better, but I am new to all this
and it may be that I'm missing something.

More information about the Haskell-Cafe mailing list