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

Timon Gehr timon.gehr at gmx.ch
Sun Nov 20 09:32:32 UTC 2022


On 19.11.22 18:29, Vladimir Panteleev wrote:
> 
> I would like to suggest the following changes for consideration:
> 
> - Replace the `$ Identifier` syntax with `: Identifier`, to match other 
> languages like Ruby and Lisp.
> 
> - The `: Identifier` syntax creates a value of a dynamic pseudo-type (a 
> bit like `typeof(null)`).
> 
>    - The type's name is `typeof(:Identifier)`.
> 
>    - The type has size 0 and holds a single value.
> 
>    - The type is implicitly convertible to any enum type which has a 
> member with the same name as `Identifier`.
> 
> I think this is a more precise and immediately implementable definition 
> of the mechanics. Not sure if a good thing or not, but this will also 
> allow using `:keyword`s stand-alone, like in Ruby/Lisp in a congruent 
> manner. For the purposes at hand (enum type inference), it will also 
> allow passing through the short-hand identifier to templated and `auto` 
> functions.

I think this makes some sense. (I especially prefer the syntax and the 
standalone symbol approach). With this proposal, we'd have to think 
about the matching level for function overloads (delegates match 
precisely even if they require inference), as with your approach one can 
overload an enum argument against a typeof(:identifier). Probably exact 
match would be better than match with implicit conversion, but idk if it 
is worth changing/bending the overloading rules over this.


More information about the Digitalmars-d mailing list