[Haskell-cafe] Newbie question about automatic memoization

Bryan Burgers bryan.burgers at gmail.com
Mon Jul 30 09:13:02 EDT 2007


On 7/30/07, peterv <bf3 at telenet.be> wrote:
> 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


More information about the Haskell-Cafe mailing list