Discussion Thread: DIP 1044--Enum Type Inference--Community Review Round 1

bachmeier no at spam.net
Fri Nov 18 22:47:19 UTC 2022


On Friday, 18 November 2022 at 21:27:51 UTC, Nick Treleaven wrote:
> On Friday, 18 November 2022 at 18:32:44 UTC, bachmeier wrote:
>>
>> ```
>> import std;
>>
>> enum JavaStyleGinormousName { a, b, c, d}
>>
>> void main() {
>>     auto var = JavaStyleGinormousName.a;
>>     writeln(var);
>>     alias B = JavaStyleGinormousName;
>>     auto var2 = B.a;
>>     writeln(var2);
>> }
>> ```
>>
>> This makes everything explicit, with no surprises and no 
>> additional learning curve for the new user. This proposal 
>> essentially boils down to an implicit
>>
>> ```
>> alias $. = [something inferred by the compiler depending on 
>> the context
>> ```
>
> alias $identifier = ExpectedType.identifier;
>
> Your example above would still need the enum type names except 
> you could write:
>
> JavaStyleGinormousName var = $a;
>
> The type name can be omitted for e.g. a function call, but then 
> you can omit the types when passing a function literal to a 
> typed function pointer parameter. Are you against function 
> literal type inference too?

I'm not following. If I pull out the example from the `Case 
statements` example and fix it so it runs, I can do this without 
any changes to the language, but I'll grant that it requires 
typing one extra character:

```
import std.stdio: writeln;

enum WordLetterOfTheDay{ a,b,c,d/*...*/ }
alias w=WordLetterOfTheDay;

void main(){
     auto letterToday = w.b;

     import std.stdio;
     switch(letterToday){
         case w.a:
             writeln("Apple");
             break;
         case w.b:
             writeln("Bicycle");
             break;
         case w.c:
             writeln("Caterpillar");
             break;
         case w.d:
             writeln("Didgeridoo");
             break;
         default:
         	break;
         /*...*/
     }
}
```

And you can still use the more verbose name if you want. I don't 
see the benefit from adding extreme levels of complexity to the 
language. I do see someone checking out the language, seeing 
this, laughing, and never looking at D again.

> The fact this feature is showing up in other systems languages 
> is evidence it is useful.

Maybe. They're different languages.



More information about the Digitalmars-d mailing list