Discussion Thread: DIP 1042--ProtoObject--Community Review Round 1
Timon Gehr
timon.gehr at gmx.ch
Sat Jan 15 18:18:06 UTC 2022
On 1/15/22 13:02, Elronnd wrote:
>
>> You can't, as any `pure` function can just call toHash.
>
> Not sure what you mean. I propose to pretend to the compiler that
> Object's constructor is pure, even though it is not (it must access
> global state to calculate a hash for the object).
>
> If the issue is that pure functions can call toHash and its output is
> 'non-deterministic' then ... I really don't have any more to say.
> toHash always returns the same result given the same input.
I said toHash can't be pure, you suggested to make the constructor cheat
so toHash can be pure. I said that does not work. I also don't have much
more to say, but maybe I can say the same thing again.
The problem is this:
```d
hash_t stronglyPure()@safe pure nothrow;
```
This returns an integer (or perhaps it throws an error). It should
always be the same integer as it is a `pure` function without any
parameters. However, it will return a different result on each
invocation if I implement it like this:
```d
hash_t stronglyPure()@safe pure nothrow{
return new Object().toHash();
}
```
I really don't care if the constructor is cheating or toHash. The point
is, you can't cheat.
More information about the Digitalmars-d
mailing list