On Sat, 6 Nov 2010 17:41:22 -0700
Jonathan M Davis <jmdavisp...@gmx.com> wrote:

> > That's probably doable, if we largely abandon the idea that the return
> > value of a pure function can be cacheable. Which I think is a bit of a
> > fanciful idea anyway.  
> 
> If they're not cacheable, what's the point of pure? I thought that that was 
> the 
> entire point. You could avoid extra calls to the function by just re-using 
> its 
> value - at least within the current expression if not the current function. I 
> quite understand avoiding caching a result for the entire run of the program 
> (if 
> nothing else, that could use up a lot of memory), but I thought that avoiding 
> extra function calls was the whole point of pure.

AFAIK, the original point of "pure" has nothing to do with efficiency, but 
instead with human capacity of understanding. Pure functions, and more 
generally avoiding state, dramatically dicreases the level of complexity. One 
can much more easily reason about a piece of code calling a pure func than a 
func does uses or changes state.
From this pov, ability to cache results is, say, a side-effect ;-) There is a 
possible intermediate position in the context of OO: allowing a "pure method" 
to change the state of the very object it is called on (this). Thus, one can 
memoize results locally (on the object itself). I like this pov, but know of no 
language that applies it.

By the way, I would enjoy some information on the optimization the compiler 
does, or will do one day, based on function purity.

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com

Reply via email to