[Haskell-cafe] Long running Haskell program

David Leimbach leimy2k at gmail.com
Wed Nov 11 14:18:27 EST 2009


On Wed, Nov 11, 2009 at 10:29 AM, David Menendez <dave at zednenem.com> wrote:

> On Wed, Nov 11, 2009 at 1:09 PM, Matthew Pocock
> <matthew.pocock at ncl.ac.uk> wrote:
> > 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)
>

That's interesting, and once I have time to come back to this part of the
project (I was behind schedule at this point!) I'll try something like that.


>
> --
> Dave Menendez <dave at zednenem.com>
> <http://www.eyrie.org/~zednenem/>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091111/1d4f0948/attachment.html


More information about the Haskell-Cafe mailing list