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

Nick Treleaven nick at geany.org
Fri Nov 18 21:27:51 UTC 2022


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?

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



More information about the Digitalmars-d mailing list