[Haskell-beginners] Relying on memoization

Russ Abbott russ.abbott at gmail.com
Fri Dec 10 05:39:32 CET 2010


(Is that even the right term?)

Let's suppose I have a fairly complex computation to perform on a data
structure. Normally I would cache the computed value in a field of the
structure. The next time I need it I don't have to compute it again. (Of
course if the structure changes, I have to recompute the value and store it
again.)

In Haskell is it the case that caching of this sort is redundant since
Haskell does it for me?  That is, if I call

f someStructure


multiple times at different places in my code and if both "f" and
"someStructure" refer to the same things each time, can I rely on Haskell
not to perform the computation multiple times but to look up the result it
previously computed?

Is there some limit to that? If every computation is stored, doesn't that
create a very large collection of stored results?
*
-- Russ *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20101209/454c21ad/attachment.htm>


More information about the Beginners mailing list