On Wed, Nov 11, 2009 at 1:09 PM, Matthew Pocock
Is there a state monad that is strict on the state but lazy on the computation? Of course, strictness in the state will force a portion of the computation to be run, but there may be significant portions of it which are not run. Would there be a way to write a state monad such that it is entirely lazy, but then to wrap either the computation or the state in an 'eager' strategy datatype which takes care of this in a more flexible manner?
I think replacing "put s" with "put $! s" should guarantee that the
state is evaluated.
If you're using get and put in many place in the code, you could try
something along these lines:
newtype SStateT s m a = S { unS :: StateT s m a } deriving (Monad, etc.)
instance (Monad m) => MonadState s (SStateT s m) where
get = S get
put s = S (put $! s)
--
Dave Menendez