[Haskell-cafe] stack overflow when using ST monad
Bulat Ziganshin
bulat.ziganshin at gmail.com
Thu Aug 24 07:52:49 EDT 2006
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)
--
Best regards,
Bulat mailto:Bulat.Ziganshin at gmail.com
More information about the Haskell-Cafe
mailing list