Type Inference for Struct/Enum Literals

IchorDev zxinsworld at gmail.com
Mon Jul 8 03:26:32 UTC 2024


On Sunday, 7 July 2024 at 19:42:25 UTC, Nick Treleaven wrote:
>
> Just to mention that Vladimir's idea of making an identifier 
> expression have its own type should work for all the cases 
> above, with minimal compiler complexity.
> https://forum.dlang.org/post/ysbmglpkvygrpjsggqco@forum.dlang.org

That’s clever actually. From memory I think Uplink’s 
implementation works/worked something like that? It would error 
with ‘cannot convert from void’ if the type inference failed (at 
least in the early versions).

Not why it was brought up, but I might as well address that their 
argument for copying Ruby and Lisp using `:` is rather weak.
Ruby doesn’t have enums as a language feature, just an 
enumeration class, so its `:` is just for generic symbol lookup.
As for suggesting to copy Lisp syntax at all, Lisp’s syntax is 
fundamentally different from D’s ALGOL-based syntax. We don’t 
`use-kebab-case` or have `(nested lists with no commas)`.
Besides that, neither language appears to use `:` for much else, 
whereas D uses colons in ways that might conflict with its 
legibility as a prefix. (See: ternary operators, named parameters)
I still think `:` is a good option, it’s just not my first pick. 
People coming from other ALGOL-style languages would naturally 
expect `.` so that would be my preference, and failing that I’d 
like to give a more contextually legible prefix a shot.

> However, that doesn't seem to help for an implicit struct 
> construction expression.

I don’t see why a similar solution couldn’t work?


More information about the dip.ideas mailing list