Attributes
William Tanksley
wtanksle@ucsd.edu
Tue, 16 Sep 1997 15:59:58 -0700 (PDT)
On Tue, 16 Sep 1997, Alaric B. Williams wrote:
> > I had thought that pure functions were a fairly well defined concept, so
> > that a function is pure if and only if every call of it with identical
> > (formal) parameters will produce identical results.
> > Of course, this probably isn't correct, since this would allow a function
> > which only modified global variables (which would then be used by other
> > functions). So let's add the requirement.
> Ah, well - but a function that "leaves a record" would surely still
> be pure,
I don't see that. If the function leaves a record then that record must
have some use, and thus the function cannot be memoized.
> just functions that reference that record would then be impure, right?
Clearly.
> There's a shade of purity.
No. Purity is absolute -- 99% pure is really 1% impure, not pure at all.
If a function is almost pure we can't memoize it at all.
Of course, if the behaviour of the function is well-defined it's easier to
manage.
> A function that marks in a
> log every application might be considered pure for reasons of
> analysing the code produced by a compiler to see if it memoises
> correctly and stuff like that... but if the function is being used
> more as a setter - ie, the mutation is part of it's "exported"
> semantics - then, indeed, it isn't quite pure any more. The
> difference there is hard to define, no? :-)
I can't understand what you're saying, aside from the fact that it has
something to do with output to a log by a putatively functional process.
However, from what I understand, I/O is considered a non-functional
process. This makes sense, since IO changes at least the coordinates of
the cursor in a global way.
>From another point of view, purity is a characteristic of the system, not
the function itself; most modern systems consider only the function's
return value when memoizing. What if the function's entire output were to
be memoized, and entire input considered? From this point of view the
whole discussion is silly, since everything (everything that Science knows
of, that is) is a pure function, with a unique cause and effect. Of
course, this point of view is useless for all practical purposes...
apparently I just like to hear the sound of my own fingers hitting the
keyboard. Oh well.
> ABW
-Billy