Writing a counter function
Sat, 29 Jun 2002 17:36:33 +0200
On Sat, Jun 29, 2002 at 06:23:27PM +0300, Shlomi Fish wrote:
> Actually, I'd like a more generalized counter. Something that would return
> both the number and a handler to add another number, which in turn would
> return the new sum and a new handler, etc.
That's just what lazy lists are for. The "handler" thing is done
automatically thanks to lazy evaluation.
I.e. countFrom n = n : countFrom (n + 1)
or just countFrom n = [n..]