Idea: partially pure functions

Bruno Medeiros brunodomedeiros+spam at com.gmail
Thu May 1 07:12:27 PDT 2008


Steven Schveighoffer wrote:
> 
> However, I tend to agree with Don.  What you want is a relaxation of the 
> rules, which can easily happen after pure functions are supported.  In fact, 
> you don't even need any new keywords or syntax, the compiler just implies 
> the partial purity from the parameter/return types.
> 

The compiler can only infer partial purity if it has access to the 
function body (just the same as it can infer normal purity). But if you 
only have a function signature, you need a keyword.

> As for your idea, to be complete, I'd say there are different levels of 
> partially pure functions.
> 
> level 1: mutable return value, but const/invariant parameters.  These 
> functions can be re-ordered, and can be called from pure or unpure 
> functions.  The result cannot be memoized.

This is already a regular pure function. The idea that a pure function 
has to return an invariant is a misconception, it can safely return 
mutable data. It can me memoized just the same (although a copy would 
have to be made if the result is not invariant)


-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list