[Haskell-cafe] [newbie question] Memoization automatic in Haskell?

Henning Thielemann lemming at henning-thielemann.de
Sat Jan 12 18:25:53 EST 2008


On Sun, 13 Jan 2008, Hugh Perkins wrote:

> On Jan 12, 2008 10:54 PM, Henning Thielemann
> <lemming at henning-thielemann.de> wrote:
> >
> > On Sat, 12 Jan 2008, Hugh Perkins wrote:
> >
> > > I guess that Haskell's referential transparence means the answers to
> > > the isPerfectSquare will be cached, ie automatically memoized? (not
> > > sure if is correct term?)
> >
> > http://www.haskell.org/haskellwiki/Memoization
>
> Interesting... but I dont understand... I thought that referential
> transparence meant that once the answer to a function has been
> calculated once, it will always be the same, and that the interpreter
> can, and will, cache this answer?

 Caching is not the default, but you can easily code this by yourself:
Define an array and initialize it with all function values. Because of
lazy evaluation the function values are computed only when they are
requested and then they persist in the array.
 One should add this most simple case to the Wiki.


More information about the Haskell-Cafe mailing list