[Haskell-cafe] Re: MonadFix

Ryan Ingram ryani.spam at gmail.com
Thu Dec 20 20:36:38 EST 2007


On 12/20/07, Joost Behrends <webmaster at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071220/771b35a5/attachment.htm


More information about the Haskell-Cafe mailing list