[Haskell-cafe] space leak when repeatedly calling Control.Monad.State.Strict.modify

Yves Parès yves.pares at gmail.com
Mon Jan 30 09:47:21 CET 2012


Have you tried to compile your code with optimisations? I guess GHC's
strictness analysis would find strict evaluation is better here.


2012/1/30 Joey Hess <joey at kitenet.net>

> Claude Heiland-Allen wrote:
> > Control.Monad.State.Strict is strict in the actions, but the state
> > itself is still lazy, so you end up building a huge thunk in the
> > state containing all the updates that ever took place to the initial
> > state.
> >
> > Using this should fix it:
> >
> > modify' :: MonadState s m => (s -> s) -> m ()
> > modify' f = do
> >   x <- get
> >   put $! f x  -- force the new state when storing it
>
> Thanks!
>
> So, why does Control.Monad.State.Strict.modify not do that?
>
> And, I still don't quite understand why this only happened
> when the updated value is obtained using IO.
>
> --
> see shy jo
>
> _______________________________________________
> 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/20120130/fe9ea59a/attachment.htm>


More information about the Haskell-Cafe mailing list