On 05/13/2010 01:22 PM, bearophile wrote:
Pelle:

It is stored as a list, and is in effect memoized.<

In practice I think Haskell doesn't memoize things there. I think it optimizes 
most things away. The main point of pure generators is indeed that they give 
the compiler enough guarantees (just as pure functions) that allow it to 
perform those optimizations safely. The point of my original post is that I'd 
like a way to give the D compiler such semantic information, mostly for 
optimization purposes (but there are other purposes, similarly to the purposes 
of pure functions).

Yes, it does. Try it!

Prelude> let fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
Prelude> fibs !! 80000

... some time passes, a huge number appears.

Prelude> fibs !! 80000

... almost instantly, the same number.

Edit the 80000 to a large enough number to slow your system down.

Note that all numbers below the large number chosen is very fast as well, once the large calculation is done.

Reply via email to