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

Nick Treleaven nick at geany.org
Sat Nov 19 17:43:57 UTC 2022


On Friday, 18 November 2022 at 22:47:19 UTC, bachmeier wrote:
> On Friday, 18 November 2022 at 21:27:51 UTC, Nick Treleaven 
> wrote:
>> 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.

I'm saying that the type inference works essentially the same as 
function literal type inference:

```d
enum LongName
{
	a,b,c
}

LongName e;
void function(int) f;

void main()
{
	f = (int i){};
	f = (i){}; // infer parameter type

	e = LongName.a;
	e = $a; // infer parent type
}
```

Given that inference is simple in both cases, why disallow it in 
only one?

> 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;

That alias is a good enough solution for a switch case with 
multiple case statements. It is however worse than the status quo 
when doing an assignment to a variable, because then you don't 
need to write the type again so a single use alias is not helping.

>> The fact this feature is showing up in other systems languages 
>> is evidence it is useful.
>
> Maybe. They're different languages.

Yes, though we have no way to avoid writing the type again for 
single uses.


More information about the Digitalmars-d mailing list