TypeFunction example: ImplictConvTargets

Stefan Koch uplink.coder at googlemail.com
Tue Oct 6 12:35:15 UTC 2020


On Tuesday, 6 October 2020 at 11:34:10 UTC, foobar wrote:
> On Tuesday, 6 October 2020 at 03:50:11 UTC, Stefan Koch wrote:
>> On Tuesday, 6 October 2020 at 00:25:40 UTC, foobar wrote:
>>> On Monday, 5 October 2020 at 21:20:36 UTC, Stefan Koch wrote:
>>>> On Monday, 5 October 2020 at 21:13:09 UTC, Paul Backus wrote:
>>>>> On Monday, 5 October 2020 at 20:57:04 UTC, Stefan Koch 
>>>>> wrote:
>>>>>> On Monday, 5 October 2020 at 12:50:39 UTC, Andrei 
>>>>>> Alexandrescu wrote:
>>>>>>
>>>>>>> [...]
>>>>>>
>>>>>> This code does not work.
>>>>>> I don't even need to compile it to see that.
>>>>>
>>>>> It has some simple mistakes, but the fundamental idea is 
>>>>> sound. Here's a version that actually compiles:
>>>>>
>>>>> import std.meta;
>>>>>
>>>>> alias Numerics = AliasSeq!(byte, ubyte, short, ushort, int, 
>>>>> uint, long, ulong, float, double, real, char, wchar, dchar);
>>>>> enum convertsTo(T, U) = is(T : U);
>>>>> alias ImplicitConversionTargets(T) = 
>>>>> Filter!(ApplyLeft!(convertsTo, T), Numerics);
>>>>>
>>>>> // prints: (int, uint, long, ulong, float, double, real, 
>>>>> dchar)
>>>>> pragma(msg, ImplicitConversionTargets!int);
>>>>> // prints: (float, double, real)
>>>>> pragma(msg, ImplicitConversionTargets!double);
>>>>
>>>> Now post it with all transitive dependencies.
>>>> And we have a fair comparison.
>>>
>>> Post your code with all changes to the language and compiler. 
>>> Then we have a fair comparison.
>>
>> Actually no.
>> The compiler changes don't affect the user.
>> They're for a small number of people to know about and support.
>> Typefunctions and CTFE are together still much less 
>> complicated than the template system is.
>>
>> I have nothing to hide though here it is
>> https://github.com/dlang/dmd/compare/master...UplinkCoder:talias_master
>>
>> 650 lines of rather clean code which can in the future be 
>> factored with the respective semantic routines.
>
> Actuallly yes.
> The language changes affect the user. This is a large change to 
> the language which puts back in the compiler what we do in 
> libraries. Whoop-de-do.
> Do type functions do anything new?

It only gives access to what the compiler has to do anyway.
It gives you an interface to what must exist within.
You could even say this makes it easier to provide a library 
implementation by using the compiler as a built-in library.
No, type functions don't do anything original they mirror how 
type manipulation works within templates providing a familiar and 
usable interface.
It is an explicit goal of mine to have type functions look just 
like any other D code.




More information about the Digitalmars-d mailing list