[Haskell-cafe] Change value of a variable

Ketil Malde ketil at malde.org
Sun Jun 7 15:26:33 EDT 2009

ptrash <ptrash at web.de> writes:

> I want to make something like a counter. I have written a recursive method
> which for example runs x times and counts how many times it runs, and also
> count some other thinks. Add the end I want a statistic about certain thinks
> returned by the method.

Keep in mind that a function's result depends only on its parameters,
so any state you want to retain must be part of the parameters.

So you might be looking for something like:

  iterateN x f y = if x == 0 then y else iterateN (x-1) f (f y)

If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell-Cafe mailing list