rust-lang / lang-team

Home of the Rust lang team
http://lang-team.rust-lang.org/
Apache License 2.0
200 stars 48 forks source link

Expand variadic generics design notes #212

Closed Jules-Bertholet closed 1 year ago

Jules-Bertholet commented 1 year ago

Adds:

Tamschi commented 1 year ago

I'm not sure where to put this, but rather than

for<T, U in Ts, Us>

I would find either of

for<(T, U) in Ts * Us> // Borrowed from scalar vector multiplication, definitely strange too though.

or

for<(T, U) in Zipped<Ts, Us>> // where `Zipped<...>` is a built-in variadic utility type accepting
                              // only tuples of tuples with the same arity as its parameter list.

more intuitively readable, as

for<T, U>

already stands for the Cartesian product of the comma-separated types.

Either would also match the syntax in for-loop expressions well in terms of symbol precedence.

Jules-Bertholet commented 1 year ago

@Tamschi

I would appreciate further discussion of my specific proposal on the Internals thread, or directly on the HackMD for smaller comments.

There are two big reasons why the design of for<... in ...> is the way it is:

scottmcm commented 1 year ago

Is there a summary of what's different from the previous note? With the file rename it's unclear to me what the additions are here.

Jules-Bertholet commented 1 year ago

The rename is its own commit, so if you review commit-by-commit you should be able to see the diff.

programmerjake commented 1 year ago

syntax bikeshedding: rather than static for use type for since it's kinda a type-level for loop since it iterates over the field types.

Jules-Bertholet commented 1 year ago

@programmerjake Please direct comments/bikeshed on my proposal specifically to the Internals thread, or directly on the HackMD for minor suggestions, so I can have it all in one place to review. (Addressing your type for suggestion: while I am not overly fond of static for, I would note that it designed to allow looping over values, lifetimes, types, and consts. type for type T in Ts would seem to me to be particularly awkward).