[Haskell-cafe] [newbie question] Memoization automatic in Haskell?
Jonathan Cast
jonathanccast at fastmail.fm
Sat Jan 12 18:21:25 EST 2008
On 12 Jan 2008, at 3:16 PM, 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,
Right.
> and that the interpreter
> can,
Right.
> and will,
Caching is not infrequently a terrible implementation strategy, for
space reasons (and sometimes for time reasons as well). Deciding
whether to use it is a delicate engineering tradeoff, and, while the
compiler will do its best, the starting point is decided by the
programmer. Lists get cached by default; functions over integers do
not. The compiler may change that decision, but it will make sure to
nail down in triplicate that doing so is an improvement for every
program subject to the optimization first, which means it probably
won't.
> cache this answer?
jcc
More information about the Haskell-Cafe
mailing list