[Haskell-cafe] Haskell and "memoization"

Gregory Crosswhite gcross at phys.washington.edu
Tue Dec 15 23:47:20 EST 2009


Hmm, you raise an 
On Dec 15, 2009, at 8:28 PM, Daniel Fischer wrote:

> Am Mittwoch 16 Dezember 2009 05:08:39 schrieb Gregory Crosswhite:
> 
> Not even then, necessarily. And it's not always a good idea.
> 
> f k = [1 .. 20^k]
> 

You raise a really good point here.  One can force sharing, as I understand it, by using a let clause:

n =
	let xs = f 20
	in length (xs ++ xs)

If I understand correctly, this should cause xs to be first evaluated, and then cached until the full length is computed, which in this case is obviously undesirable behavior.

Cheers,
Greg



More information about the Haskell-Cafe mailing list