Stack usage with a state monad
Joe Thornber
thornber at sistina.com
Wed Dec 31 12:36:33 EST 2003
On Wed, Dec 31, 2003 at 11:54:27AM +0000, 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 monad?
>
> But why does this computation have be done in a state monad at
> all? countLeaves seems to me to be a pretty straightforward function from
> a Tree to an Int, with no need for intervening state other than to
> increment a counter: as such, I'd have expected a simple recursive
> function to serve the purpose. (Maybe there was something in the original
> application that was lost in the problem isolation?)
I think you might well be correct that I'm doing things the wrong way.
The original program is a chess prog. and the function in question is
the alphabeta search. I wanted to hold the transposition table (a
cache of seen positions) among other things in the state monad. I
thought this was the normal way to approach this, but am having doubts
now. The recursive approach will indeed work, but I had hoped to
avoid all the code associated with threading the state by hand.
- Joe
More information about the Haskell-Cafe
mailing list