On 12/20/07, Joost Behrends <webmaster@h-labahn.de > wrote:
makes a DESTRUCTIVE UPDATE of the DivIters (by put) and this kind of recursion
seems not to "remember" itself (as i have understood, that is achieved by
"tail recursion"). I just didn't like making DivIters to States.
It's kind of lying code.
 
I just want to point out that this isn't true; "put" in the State monad doesn't do any destructive update at all (unlike, for example, IORef).
 
You can tell this for yourself by looking at the type of "State s a" in Control.Monad.State:
http://haskell.org/ghc/docs/latest/html/libraries/mtl/src/Control-Monad-State-Lazy.html
 
newtype State s a = State { runState :: s -> (a,s) }
 
That is, your "divisions" function of type
  divisions :: State DivIter DivIter
is equivalent to the type
  runState divisions :: DivIter -> (DivIter, DivIter)
and the code is the same as if you'd just passed the DivIter directly along.
 
  -- ryan