[Haskell-cafe] stack overflow when using ST monad

Gregory Wright gwright at comcast.net
Thu Aug 24 08:22:40 EDT 2006


Hi Bulat,

On Aug 24, 2006, at 7:52 AM, Bulat Ziganshin wrote:

> Hello Gregory,
>
> Thursday, August 24, 2006, 2:29:15 PM, you wrote:
>
>> step t = do
>>          c <- readSTRef (count t)
>>          s <- readSTRef (state t)
>>          writeSTRef (count t) (c - 1)
>>          writeSTRef (state t) (nextState s)
>>          if (c <= 0) then return Nothing else return (Just c)
>
> as Chris said, you are write unevaluated chunks.
>
> add $! to evaluate values before writing:
>
>           writeSTRef (count t) $! (c - 1)
>           writeSTRef (state t) $! (nextState s)
>

That fixed it exactly.  Thank you Bulat and Chris!

Best Wishes,
Greg


> -- 
> Best regards,
>  Bulat                            mailto:Bulat.Ziganshin at gmail.com
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list