
1 May
2007
1 May
'07
10:10 p.m.
DavidA wrote:
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?
Here is one way: For functions that do not need IO, use types that look like: MonadState GameState m => ... -> m a For functions that only do IO without refering to the game state, use: MonadIO m => ... -> m a For functions that do both, use: (MonadIO m, MonadState GameState m) => ... -> m a Testing of the pure game functions can use State GameState, testing of pure IO functions can use IO, and production can use StateT GameState IO. -Yitz