[Haskell-cafe] Re: Memoization in Haskell?
Heinrich Apfelmus
apfelmus at quantentunnel.de
Fri Jul 9 03:50:30 EDT 2010
Gregory Crosswhite wrote:
> You're correct in pointing out that f uses memoization inside of itself
> to cache the intermediate values that it commutes, but those values
> don't get shared between invocations of f; thus, if you call f with the
> same value of n several times then the memo table might get
> reconstructed redundantly. (However, there are other strategies for
> memoization that are persistent across calls.)
It should be
f = \n -> memo ! n
where
memo = ..
so that memo is shared across multiple calls like f 1 , f 2 etc.
Regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
More information about the Haskell-Cafe
mailing list