[Haskell-cafe] Solving a geometry problem with Haskell

Cale Gibbard cgibbard at gmail.com
Mon Jan 14 01:10:43 EST 2008


On 12/01/2008, Hugh Perkins <hughperkins at gmail.com> wrote:
> On Jan 12, 2008 10:19 PM, Rafael Almeida <almeidaraf at gmail.com> wrote:
> > After some profiling I found out that about 94% of the execution time is
> > spent in the ``isPerfectSquare'' function.
>
> 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?)

This isn't true unless calling isPerfectSquare reads the result out of
a lazily generated array of responses or some other data structure at
the top-level. There's no memoisation of functions by default because
it would typically require ridiculous amounts of memory, however, you
can usually rely on values bound to variables to only be computed
once, barring those which are typeclass polymorphic.

 - Cale


More information about the Haskell-Cafe mailing list