
30 Jul
2007
30 Jul
'07
9:13 a.m.
On 7/30/07, peterv
Does Haskell support any form of automatic memorization?
For example, does the function
iterate f x
which expands to
[x, f(x), f(f(x)), f(f(f(x))), …
gets slower and slower each iteration, or can it take advantage of the fact that f is referentially transparent and hence can be "memoized / cached"?
Thanks, Peter
For 'iterate' the answer does not really need to be memoized. I imagine the definition of 'iterate' looks something like this: iterate f x = x : iterate f (f x) So f isn't being applied n times to x for the n+1st element, rather, it's being applied once to the nth element for the n+1st element. Bryan