Stack usage with a state monad

2003-12-30 Thread Joe Thornber
Hi, I was wondering if anyone could give me some help with this problem ? I'm trying to hold some state in a StateMonad whilst I iterate over a large tree, and finding that I'm running out of stack space very quickly. The simplified program below exhibits the same problem. This is the first tim

Re: Stack usage with a state monad

2003-12-30 Thread Tomasz Zielonka
On Tue, Dec 30, 2003 at 02:12:15PM +, Joe Thornber wrote: > Hi, > > I was wondering if anyone could give me some help with this problem ? > I'm trying to hold some state in a StateMonad whilst I iterate over a > large tree, and finding that I'm running out of stack space very > quickly. The

Re: Stack usage with a state monad

2003-12-30 Thread Koji Nakahara
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

Re: Stack usage with a state monad

2003-12-30 Thread Tomasz Zielonka
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 >>,

Re: Stack usage with a state monad

2003-12-30 Thread Joe Thornber
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 bet

Re: Stack usage with a state monad

2003-12-31 Thread Graham Klyne
I've read 4 messages following this, but I'd like to pursue this a little to test my own understanding... At 14:12 30/12/03 +, Joe Thornber wrote: I was wondering if anyone could give me some help with this problem ? I'm trying to hold some state in a StateMonad whilst I iterate over a large

Re: Stack usage with a state monad

2003-12-31 Thread Joe Thornber
On Wed, Dec 31, 2003 at 11:54:27AM +, Graham Klyne wrote: > My *intuition* here is that the problem is with countLeaves2, in that it > must build the computation for the given [sub]tree before it can start to > evaluate it. Maybe this is why other responses talk about changing the > state m

Re: Stack usage with a state monad

2003-12-31 Thread Graham Klyne
At 12:36 31/12/03 +, Joe Thornber wrote: On Wed, Dec 31, 2003 at 11:54:27AM +, Graham Klyne wrote: > My *intuition* here is that the problem is with countLeaves2, in that it > must build the computation for the given [sub]tree before it can start to > evaluate it. Maybe this is why other r

Re: Stack usage with a state monad

2003-12-31 Thread Joe Thornber
On Wed, Dec 31, 2003 at 02:38:06PM +, Graham Klyne wrote: > getOrCachePositionValue pos = > do { mcache <- gets (findPos pos) -- Query cache for position >; case mcache of >Just cached -> return (cachedVal cached) -- Return cached value >Nothing ->

Re: Stack usage with a state monad

2004-01-02 Thread Graham Klyne
At 15:37 31/12/03 +, Joe Thornber wrote: On Wed, Dec 31, 2003 at 02:38:06PM +, Graham Klyne wrote: > getOrCachePositionValue pos = > do { mcache <- gets (findPos pos) -- Query cache for position >; case mcache of >Just cached -> return (cachedVal cached) -- Ret

Re: Stack usage with a state monad

2004-01-02 Thread Joe Thornber
On Fri, Jan 02, 2004 at 02:46:04PM +, Graham Klyne wrote: > If your calculation really needs to update the cache state as it goes > along, then I agree that it needs to be run in the state monad. But even > then, I'd be inclined to look for sub-calculations that can be evaluated as > ordina