> Here is my situation: I have a state monad. It seems to me that
> if states are built out of lazy types, then there may be many
> states all live at the same time, thus blowing up the space.
> But deep in my state data types, I have strings. Also some
> monad operations return strings. So I need strict strings.
>
> In case I haven't made this clear, here is an example:
>
> example =
> do some_string <- a_function_of_state
> modify_the_state
> modify_the_state_some_more
> do_something_with_a_string some_string
>
> Now if I run example on a state s0, then s0 will be live throughout
> the execution of example, whereas, if "a_function_of_state" returned
> a completely evaluated data structure and a completely updated the
> state, then the parts of s0 that are not shared should be collectable.
It depends on the particular state monad. In the GHC/Hugs libraries,
IO and ST are strict
LazyST is lazy
A strict state monad means is that there is only one state.
So in your program, modify_the_state won't happen until a_function_of_state
has exectued at least all stuff which affects the state. The
"strict" part is that all computations are strict in the state.
So modify_the_state evaluates its input state, forcing all the earlier
statful
operations to take place.
Of course, some_string might still have unevaluated thunks that
don't involve the state.
Simon