Expanding the horizons of D purity

Kenji Hara k.hara.pg at gmail.com
Fri Nov 1 07:21:40 PDT 2013


2013/11/1 Timon Gehr <timon.gehr at gmx.ch>

> On 11/01/2013 02:36 PM, Kenji Hara wrote:
>
>> I think this is a good discovery. Currently a pure function can have
>> lazy parameters and it is treated as a weakly pure function.
>>
>> pure int foo(lazy int x) { return x; }  // OK
>>
>> We can think the lazy parameter is a limited case of scope delegate
>> parameter.
>> ...
>>
>
> They are. I think it would be quite strange to treat them differently.


I've also felt same thing about it. The proposal will generalize the
language rule.


>  And more, I discovered that the purity may be stronger depends on the
>> given delegate purity.
>>
>> void func(scope void delegate(int) dg) pure;
>>
>> void main() {
>>      int num;
>>
>>      // the function call has weak purity
>>      func((x){ num = x;});
>>
>>      // the function call has strong purity
>>      func((x){ ; });
>> }
>>
>> Kenji Hara
>>
>>
> Yes. Furthermore, the first delegate should have inferred type 'void
> delegate(int x)pure nothrow @safe' and the second delegate should have
> inferred type 'void delegate(int x)pure immutable nothrow @safe'.
>

The first delegate should not become pure. So it would become 'void
delegate(int)nothrow @safe'. I agree with the second inference result.

Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20131101/3be296a1/attachment.html>


More information about the Digitalmars-d mailing list