Stack usage with a state monad
Joe Thornber
thornber at sistina.com
Tue Dec 30 20:13:16 EST 2003
On Tue, Dec 30, 2003 at 08:28:11PM +0100, Tomasz Zielonka wrote:
> On Wed, Dec 31, 2003 at 02:54:18AM +0900, Koji Nakahara wrote:
> > Hi,
> >
> > I think the problem is in the State Monad itself;
> > State Monad is lazy to compute its state.
> >
> > I am not a haskell expert, and there may be better ideas. But anyhow,
> > when I use these >>>= and >>> instead of >>= and >>,
> > your example runs fine. I hope it becomes some help.
> >
> > m >>>= k = State $ \s -> let (a, s') = runState m s
> > in s `seq` runState (k a) s' -- force evaluation of the state
> >
> > m >>> k = m >>>= \_ -> k
>
> Ahh, right. So I didn't have to use UnboxedState. StrictState would do.
Thankyou both for your help, I wouldn't have thought of changing the
State monad itself. I guess I've got lots more to learn :)
- Joe
More information about the Haskell-Cafe
mailing list