
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 -- John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/