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) -- Return

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 ordinary

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

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

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

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 -

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

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 - let (a,

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 , your example

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 better ideas.