November 07, 2013 Re: Expanding the horizons of D purity | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Shelomovskij | On Thu, Nov 07, 2013 at 09:22:47PM +0400, Denis Shelomovskij wrote: > 01.11.2013 0:05, H. S. Teoh пишет: > >I'd like to propose extending the scope of weak purity one step further: allow weakly-pure functions to call (not necessarily pure) delegates passed as a parameter. > > Unacceptable. It will break strongly purity. Your mistake is strongly pure function can easily get an impure delegate: [...] It will not. My proposal only applies to weakly pure functions. Strongly pure functions cannot call impure delegates because you cannot guarantee anything about what the delegate will do. So basically, once a pure function takes a non-pure delegate parameter, it is no longer strongly pure, only weakly pure. (I stated this at the end of my post where strongly pure functions are not allowed to call impure delegates.) T -- Never trust an operating system you don't have source for! -- Martin Schulze |
November 07, 2013 Re: Expanding the horizons of D purity | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Shelomovskij | On 11/07/2013 06:22 PM, Denis Shelomovskij wrote:
> 01.11.2013 0:05, H. S. Teoh пишет:
>> I'd like to propose extending the scope of weak purity one step further:
>> allow weakly-pure functions to call (not necessarily pure) delegates
>> passed as a parameter.
>
> Unacceptable. It will break strongly purity. Your mistake is strongly
> pure function can easily get an impure delegate:
> ---
> ...
As far as I understood, he proposes to disallow constructing impure delegates inside pure functions.
|
November 11, 2013 Re: Expanding the horizons of D purity | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | 07.11.2013 21:41, H. S. Teoh пишет: > On Thu, Nov 07, 2013 at 09:22:47PM +0400, Denis Shelomovskij wrote: >> 01.11.2013 0:05, H. S. Teoh пишет: >>> I'd like to propose extending the scope of weak purity one step >>> further: allow weakly-pure functions to call (not necessarily pure) >>> delegates passed as a parameter. >> >> Unacceptable. It will break strongly purity. Your mistake is >> strongly pure function can easily get an impure delegate: > [...] > > It will not. My proposal only applies to weakly pure functions. Strongly > pure functions cannot call impure delegates because you cannot guarantee > anything about what the delegate will do. > > So basically, once a pure function takes a non-pure delegate parameter, > it is no longer strongly pure, only weakly pure. (I stated this at the > end of my post where strongly pure functions are not allowed to call > impure delegates.) > > > T > Let me repeat my code again: --- int i; struct S { void g() { ++i; } } void impureCaller(scope void delegate() del) pure { del(); } void f() pure // strongly pure, will modify `i` { S s; impureCaller(&s.g); } --- Currently the only error is in `impureCaller` body. You propose to make `impureCaller`'s body valid thus making the code compilable. Do you also propose some breaking changes to make `f` body invalid? I see no "breaking changes" notes in you "nutshell" at the end. Looks like you either didn't think enough about such cases or you propose to make it impossible to detect whether the function is strongly pure by it's signature. -- Денис В. Шеломовский Denis V. Shelomovskij |
November 13, 2013 Re: Expanding the horizons of D purity | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Shelomovskij | On Tue, Nov 12, 2013 at 12:06:25AM +0400, Denis Shelomovskij wrote: > 07.11.2013 21:41, H. S. Teoh пишет: > >On Thu, Nov 07, 2013 at 09:22:47PM +0400, Denis Shelomovskij wrote: > >>01.11.2013 0:05, H. S. Teoh пишет: > >>>I'd like to propose extending the scope of weak purity one step further: allow weakly-pure functions to call (not necessarily pure) delegates passed as a parameter. > >> > >>Unacceptable. It will break strongly purity. Your mistake is strongly pure function can easily get an impure delegate: > >[...] > > > >It will not. My proposal only applies to weakly pure functions. Strongly pure functions cannot call impure delegates because you cannot guarantee anything about what the delegate will do. > > > >So basically, once a pure function takes a non-pure delegate parameter, it is no longer strongly pure, only weakly pure. (I stated this at the end of my post where strongly pure functions are not allowed to call impure delegates.) > > > > > >T > > > > Let me repeat my code again: > --- > int i; > > struct S > { void g() { ++i; } } > > void impureCaller(scope void delegate() del) pure > { del(); } > > void f() pure // strongly pure, will modify `i` > { > S s; > impureCaller(&s.g); > } > --- > > Currently the only error is in `impureCaller` body. You propose to make `impureCaller`'s body valid thus making the code compilable. Do you also propose some breaking changes to make `f` body invalid? [...] It should be illegal to take the address of S.g in f() if f is pure. T -- You have to expect the unexpected. -- RL |
Copyright © 1999-2021 by the D Language Foundation