Expanding the horizons of D purity

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Nov 1 10:12:06 PDT 2013


On Fri, Nov 01, 2013 at 08:59:29PM +0400, Denis Shelomovskij wrote:
> 01.11.2013 0:05, H. S. Teoh пишет:
[...]
> >So, in a nutshell, my proposal is:
> >
> >- Functions that, besides invoking a delegate parameter, are pure,
> >  should be allowed to be marked as pure.
> >
> >- Template functions that, besides invoking a delegate parameter,
> >  perform no impure operations should be inferred as pure.
> >
> >- A function that takes a delegate parameter cannot be strongly pure
> >  (but can be weakly pure), unless the delegate itself is pure.
> >  (Rationale: the delegate parameter potentially involves arbitrary
> >  references to the outside world, and thus cannot be strongly pure.)
> >
> >
> >T
> >
> 
> The code you like to make working looks good but I'm against the
> language change. I'd say the issue is nested pure functions aren't
> allowed to access outer function variables. Filed as Issue 11412.
[...]

No, that's not good enough. What if you need to pass an impure delegate
to toString()? Sure, std.format can be made to use only pure delegates,
but you can't predict other code that needs to use toString. Forcing
toString to take only pure delegates makes it unusable with output
ranges that need to perform impure operations. With my proposal,
toString will work with *both* pure and impure delegates -- basically,
the pure qualifier becomes a dependent purity ("purity of this function
depends on the delegate parameter, body of function is pure besides the
invocation of the delegate").


T

-- 
Кто везде - тот нигде.


More information about the Digitalmars-d mailing list