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

DavidA polyomino at f2s.com
Tue May 1 05:20:26 EDT 2007


> 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.)

I'm also interested in the answer to this question. One concern I would have 
about option 2 is that it looks like it "breaks encapsulation", to use a phrase 
from OOP.

What I mean is, it seems like good design would mean that you could write and 
test the game logic totally independently of any IO. Game functions such 
as "makeMove" ought to have type signatures that don't involve any IO. Can this 
be achieved in option 2?




More information about the Haskell-Cafe mailing list