Purity
spir
denis.spir at gmail.com
Sat Dec 18 03:52:57 PST 2010
On Sat, 18 Dec 2010 01:08:20 -0800
Jonathan M Davis <jmdavisProg at gmx.com> wrote:
Thank you for the explanation about strongly pure funcs calling weakly pure ones --this fully makes sense.
> > I would like weakly pure to include output funcs, and exclude all
> > possibilities to modify (non-local) state.
>
> The problem is that output is accessing global variables - which weakly pure
> functions _cannot_ do.
Why? What is the rationale for excluding output (I don't mean I/O, only O)?
> If you call a weakly pure function from a strongly pure
> function, it's still guranteed that the result of the strongly pure function
> will be the same and have _no_ side effects - that is, it effectively has the
> functional definition of purity. However, if you allowed I/O, you then have a
> side effect, and two calls to a particular strongly pure function could differ,
> and yet the optimizer would then only do one call, thereby changing the results
> of the program.
I disagree. Again, I'm not talking of I/O. The FP definition of "pure" excluding output is irrational imo. Writing to output cannot change later function return values, so who cares?
And it's not only true for debug --even if I very much agree debug is a super important reason for allowing output.
Denis
-- -- -- -- -- -- --
vit esse estrany ☣
spir.wikidot.com
More information about the Digitalmars-d
mailing list