Type Inference for Struct/Enum Literals
Steven Schveighoffer
schveiguy at gmail.com
Sat Jul 6 02:49:32 UTC 2024
On Friday, 5 July 2024 at 13:19:44 UTC, IchorDev wrote:
> - The `.` syntax feels natural for enum literals, but not for
> struct literals. This would have to mean changing the module
> scope operator (perhaps to `./`? (Like to how `./` represents
> 'here' in a terminal) because otherwise module-level symbols
> would interfere.
> - My original proposal used `$`, which I still like for struct
> literals, but it's a bit random.
> - I don't like the C initialiser syntax (`{}`) but it could be
> re-purposed for type-inferred struct literals, which would mean
> we can basically merge the two.
OK, so in fact, we have an interesting possibility here. With
editions we *could* potentially overtake the `.` prefix, and use
something else for global scope.
The biggest problem with this is -- it breaks all existing
knowledge of what this does. It is, for sure, the most natural
syntax for this feature. One might argue that `$.symbol` could
mean "global symbol" instead (or something else).
It's a pretty big lift for this, and I don't see it being
accepted. Already there is pushback from the language maintainers
on the concept itself (from the original review).
However, I would love to see this inference piece get into the
language, whatever the syntax. I very much enjoyed it in my swift
programs. I would guess that the best possibility to be accepted
would be to have syntax that doesn't conflict with existing
syntax.
-Steve
More information about the dip.ideas
mailing list