Can we make mixin applications first class at the type level?

sighoya sighoya at gmail.com
Thu Mar 21 11:10:27 UTC 2019


On Thursday, 21 March 2019 at 10:11:34 UTC, Stefan Koch wrote:
> On Wednesday, 20 March 2019 at 17:34:49 UTC, sighoya wrote:
>> Allowing
>>
>> mixin template GenInt()
>> {
>>     const char[] type="Int";
>> }
>>
>> { ... }
>
> I am already working on proper first class types for D.

Awesome. Wouldn't it complicate the grammar of D?,e.g.:

int * p; // does it mean declaring an int or calling * : 
(Type,Type)->(Type,Type)
> Which don't have to go through strings to work.

It would be much more of semantic than handling with strings.

> However this work is progressing very slowly as my day-job and 
> newCTFE have higher priority.

Understand, is there any repo where you work on first class types?

> Using strings and mixins to emulate first-class types may work 
> for some cases but will inevitably fall short for others.

I don't how you want to implement first class types, but type 
comparison would trigger anyway pointer comparison of strings.
But steady converting type to string to type is ugly with the 
mixin solution, but better than nothing.
We have currently limited type calculus with AliasSeq which is 
however complicated to use and  very limited.

> I'd be interested in your usecase so I can add more do the 
> motivation section of my future DIP draft.

Nice, beside mapping of types it would be nice to switch case 
over them:

switch(typeof(expr))
{
case int:

case float:
}

instead of creating enums tediously.
> Cheers,
> Stefan


>For reasoning about code and hygiene, the use site has to 
>indicate to the programmer that code is being inserted into the 
>current scope, rather than just calling a function.

Hygiene isn't the problem as mixins are semi hygenic, in case of 
collision the collided parts get scoped.

Further, when we already annotate a template as mixin, then it is 
clear that it will be expanded. it would only make sense for a 
template without mixin annotation.

>In my editor (Geany/Scintilla) q{} contents are highlighted like 
>code:

Yes, but fortunately most written code isn't wrapped inside a 
quote environment ;).

But quoting is a good solution for AST parsing though. However, I 
don't understand why the people here don't like macros, they 
would be much more idiomatic than STRING MIXINS!!!

>The syntax could be tweaked so `$ident!targs(args)` expands to 
>`mixin(ident!targs(args))`.

OMG is this ugly!



More information about the Digitalmars-d mailing list