[Haskell-beginners] When, if ever, does Haskell "calculate once"?

Chaddaï Fouché chaddai.fouche at gmail.com
Mon May 10 09:21:42 EDT 2010

On Thu, May 6, 2010 at 9:37 PM, Brent Yorgey <byorgey at seas.upenn.edu> wrote:
>> data MyList a = MyList {mylist::[a], mylength::Int}
> There's no magic going on here, if you call a function to compute some
> complicated feature of a data structure multiple places in your code,
> it will be computed multiple times, just like in any other language.
> Caching the features you need as in the above example is a good idea
> if the data structures won't change often, and you really do need the
> features many times.

Notice that if you don't need mylength anywhere in your code, it won't
be computed (except if you made your smart constructor extra-strict)
so it's way easier in Haskell to implement the "compute this only once
but only if I really need it" scheme that you often see in other


More information about the Beginners mailing list