Consistent syntax for generic parameters


#1

Currently you have to write path<...> in type contexts and path::<...> in expressions. As a C++ user and a new user of Rust forgetting the :: in expressions is one of the most common errors I make. This is made worse by the fact that the error messages when making this error aren’t obvious. I’ll probably get used to this eventually, but it’s certainly not an inviting trait.

To solve this we need an unified syntax across both types and expressions. However freeing up <, and > isn’t an acceptable solution. It has a strong precedent set by maths. Neither is using (...) since we really want that for calls. {...} is taken by object literals and would probably be a bit noisy for generics. That leaves us [...] which is currently used for indexing. Given that indexing takes two operands, it doesn’t strictly need matching braces. Rust also have strong functional programming influences which would hopefully make indexing less pervasive than in C. I’ve yet to see it in Rust code, but that may have something to do with it supposedly being broken. I feel it’s preferable to free up [...] for generics which would be way more common than indexing in idiomatic Rust code.

Feel free to bikeshed an alternative syntax for indexing. Some suggestions:

vec'0
vec'i
vec'(i + 1)

vec'0
vec'i
vec'(i + 1)

vec\0
vec\i
vec\(i + 1)

vec#0
vec#i
vec#(i + 1)

#2

There was an RFC about changing the <> back to [] for generics, which also spawned a reddit thread.

Finally, the RFC got closed by its author:


Regarding your proposed changes, I think is going to be really hard to convince people to change both [] indexing and <> for generics, given their strong prevalence in PLs due to the C/C++ tradition.

That being said, of your indexing syntax proposals, the last one vec#0 looks less awkward to me.