Is there any chance to introduce concepts/traits/typeClasses in dlang?

rikki cattermole rikki at cattermole.co.nz
Mon Dec 16 02:35:50 UTC 2019


On 16/12/2019 9:07 AM, sighoya wrote:
>> That is the static introspection capabilities.
>> For dynamic:
>>
>> // typeof(input) is still templated, its just hidden, since only the 
>> template arguments need deducing
>> InputRange!ElementType map(alias func)(auto:InputRange input) if (...) {
>>     struct Voldemort {
>>         ...
>>     }
>>
>>     return ...; // auto construction of an InputRange instance with 
>> deduction of what ElementType is.
>> }
> 
> Im not quite aware of the meaning of auto:InputRange but in my eyes it 
> is static dispatching too, I find it equivalent too:
> 
> InputRange!ElementType map(alias func,ElemType)(InputRange!ElemType 
> input){...}

Whatever map returns, can be initialized to the InputRange signature.
That is what auto:Signature means. Where Signature can be although 
doesn't have to be template initialized.

I think this is quite nice syntax, as it works in the function 
parameters and it is easily recognized by the parser because keyword 
auto then ':' then some type.

What you changed it to, is using runtime dispatch instead of static.
Another form I've come up with for static is ``is(T : Signature)``. With 
same meaning as ``auto:Signature`` but requires template constraints to 
mean the same thing.


More information about the Digitalmars-d mailing list