Discussion Thread: DIP 1044--Enum Type Inference--Community Review Round 1
Vladimir Panteleev
thecybershadow.lists at gmail.com
Sat Nov 19 17:29:11 UTC 2022
On Friday, 18 November 2022 at 15:37:31 UTC, Mike Parker wrote:
> ## Discussion Thread
>
> This is the discussion thread for the first round of Community
> Review of DIP 1044, "Enum Type Inference":
[half feedback, half random brainstorming, so posting here to be
safe]
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.
It will not allow
```d
myFn($a + $a); // passes A.b
```
to work, but I'm not sure that would be implementable anyway in a
reasonable manner and provide justifiable value. I think the
remaining examples in the DIP will continue to work.
On another point, since the DIP mentions the `with` approach,
I'll mention that the workaround I've been using is to declare a
short local alias for the enum type. At the top level (e.g. for
variable/constant initializers), it can be done by wrapping the
value in a CTFE function:
https://gist.github.com/CyberShadow/54ca7a0fa594c2272cabf8677ff6e42f#file-game-d-L150
More information about the Digitalmars-d
mailing list