[Haskell-cafe] Re: Re: Can we come out of a monad?
john at repetae.net
Fri Jul 30 19:02:53 EDT 2010
On Fri, Jul 30, 2010 at 11:57:00AM -0500, Jason Catena wrote:
> By this example State doesn't seem to give you anything more than a
> closure would, since it doesn't act like much of an accumulator (by,
> for example, storing 6 as its new internal value).
> Could you use State for something like storing the latest two values
> of a Fibonacci series? For example, each time you call it, it
> generates the next term, discards the oldest term, and stores the
> newly-generated term?
Although state can't be used to calculate things that couldn't be
calculated otherwise, it can be used to implement things faster (in a
real, computer theoretic sense) than they could be otherwise. For
instance, the union-find algorithm cannot be implemented efficiently
without state, the state monad allows the best of both worlds, a pure
interface but the fast algorithm under the hood.
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/
More information about the Haskell-Cafe