Skip to content

Reconsider struct initialization syntax #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lolbinarycat opened this issue Apr 3, 2025 · 1 comment
Closed

Reconsider struct initialization syntax #202

lolbinarycat opened this issue Apr 3, 2025 · 1 comment

Comments

@lolbinarycat
Copy link

In Rust (which vine takes significant syntax inspiration from), the token : is used for two things:

  • Giving types to things
  • Initialization of structs

With 10+ years of hindsight, I think we can pretty definitively conclude this is a mistake.
The biggest problem is how this interferes with the type ascription,
so much so that type ascription as a feature was scrapped.

Another point of reference is Carbon, a language that also takes a lot of syntax inspiration from Rust, does not use : in struct literals.

This allows it to have more natural type ascription, which is especially noticeable for things like tuples.

Rust: let (x, y): (u8, u32) = (1, 2)

Carbon: let (x: u8, y: u32) = (1, 2)

@tjjfvi
Copy link
Member

tjjfvi commented Apr 3, 2025

I recognize the reasons against using it for objects, and I have considered alternatives, but ultimately I decided this was the best option.

I will note that Vine does have type ascription within patterns:

let (x: N32, y: String) = (1, "abc");
let { a:: Bool, b:: Char } = { a: true, b: '!' };

(The a:: Bool is shorthand for a: a: Bool, which is the type-ascripted analogue to the a shorthand for a: a. The :: is somewhat unfortunate, but the alternatives are all worse IMO.)

@tjjfvi tjjfvi closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants