Combining IO and state monads

Andrew J Bromage ajb@spamcop.net
Mon, 19 May 2003 14:01:14 +1000


G'day all.

On Sat, May 17, 2003 at 12:30:11PM +0100, Ganesh Sittampalam wrote:

> Also, I strongly recommend the use of a record to keep your state - if you
> use a tuple, then each time you add something new you'll have to change all
> the getters and setters (or any other code that acts directly on the
> structure of the state).

One thing that I've also found useful is to stack a ReaderT on top of
IO, and store a record of IORefs in the ReaderT state.  This way, not
only is it extensible, but you don't pay the cost of repacking the state
tuple in code that modifies state a lot.  You could, of course, also do
this with STRefs.

Cheers,
Andrew Bromage