Why is D unpopular, redux.
Timon Gehr
timon.gehr at gmx.ch
Tue May 24 23:21:44 UTC 2022
On 24.05.22 07:00, Walter Bright wrote:
> On 5/22/2022 3:37 AM, Timon Gehr wrote:
>>>> Just on type qualifiers:
>>>> - Transitivity of type qualifier doesn't play nice with template.
>>>> There is no way to tell the compiler that a `const Tpl!T` actually
>>>> is a `const Tpl!(const T)`. As a result, no container library is
>>>> possible and ranges have serious problem when it come to qualifiers
>>>> too.
>>>
>>> This needs a lot more fleshing out about what exactly is wrong and why.
>>> ...
>>
>> Instances of the same struct/class template are independent types
>> without any relationship. Different types of slices (for example) are
>> not.
>
> Illuminating examples, please.
> ...
For containers: Just consider a struct wrapping a built-in slice.
struct Slice(T){
T[] slice;
}
T[] is a subtype of const(T)[], but Slice!T is not a subtype of
Slice!(const(T)). In general this cannot be guaranteed, but containers
may need to be able to allow this kind of conversions.
For ranges:
E.g., here, x is a const slice and can be mapped. The resulting const
value cannot be used as a range anymore.
```d
import std.algorithm;
void main(){
const x=[1,2,3,4];
const y=x.map!(v=>2*v); // ok
const z=y.map!(v=>2*v); // error
}
```
This kind of thing should just work, but there is no way to strip away
the topmost const for a MapResult.
(There is probably an unrelated Phobos bug as well, as the error happens
in the guts of Phobos.)
>
>> There is no way to declare a tail-immutable class reference.
>>
>> immutable(int)* <- can rebind the reference, can't assign to value
>>
>> immutable(Class) <- can't rebind the reference
>> Class <- can rebind the reference, can assign to value
>
> Should file an Enhancement Request on Bugzilla.
There's e.g. this one: https://issues.dlang.org/show_bug.cgi?id=5325
More information about the Digitalmars-d
mailing list