[email protected] wrote:
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.
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.
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.
Haskell-Cafe mailing list