[Haskell-cafe] Re: Why doesn't laziness save the day here?

Dale Jordan dalej at alum.mit.edu
Thu Jan 7 14:35:32 EST 2010

oleg at okmij.org wrote:
> The others have already pointed out the problem with the imperative
> solution, which used the mutation of the global state with the new
> random seed. Imperative approach is indeed often a problem.
As Daniel Fischer pointed out, my immediate problem was that iterateR 
never finished, even though it did produce results lazily.  I missed the 
subtlety that access to results didn't mean access to the state.

> There is a simple solution however.
[Snipped ASCII art of head exploding...]

> module RList where
[Nice code snipped]

So, if I may paraphrase, oleg's solution works by reifying the implicit 
continuation in my iterateR's recursive definition into a data structure 
that is explicitly forced with pullR and its callers.  Fascinating...

Thanks to all who responded.


More information about the Haskell-Cafe mailing list