Can we just have struct inheritence already?

Timon Gehr timon.gehr at gmx.ch
Fri Jun 14 12:26:11 UTC 2019


On 14.06.19 04:10, Walter Bright wrote:
> On 6/13/2019 5:35 PM, Timon Gehr wrote:
>> It is obvious that allocation has to be pure. However, accessing the 
>> address of your data is impure. The runtime systems of pure functional 
>> languages also allocate memory, but the addresses are not exposed to 
>> the pure user code.
> 
> I know that technically you are correct, but I'm not so sure it matters 
> for D's use of purity.

`pure` in D already provides value. It would provide more value if it 
also restricted access to addresses.

In any case, the spec currently states:

`For cases where the compiler can guarantee that a pure function cannot 
alter its arguments, it can enable full, functional purity (i.e. the 
guarantee that the function will always return the same result for the 
same arguments).`

This is blatantly wrong if `pure` functions and your notion of "the same 
result" are able to access memory addresses. If your notion of "the same 
arguments" is able to access memory addresses, the guarantee is 
basically meaningless (and still does not exist).


If I see:
int foo(immutable(int)[] a)pure;

I want to be able to assume the result of `foo` is a function of the 
length and elements of `a`. This is currently not the case and it 
bothers me.


More information about the Digitalmars-d mailing list