Skip to content

Commit 5f52e38

Browse files
committed
Explicitly allow (...Front, Last) and similar
1 parent 8114d4c commit 5f52e38

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

text/0000-variadic-generics.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ implementations of `Tuple` will be added. This enables an increased level of
7979
negative reasoning making it easier to write blanket implementations of traits
8080
for tuples.
8181

82-
## The `(Head, ...Tail)` Type Syntax
83-
This syntax would allow for a `Cons`-cell-like representation of tuple types.
84-
For example, `(A, ...(B, C))` would be equivalent to `(A, B, C)`. This allows
85-
users to represent the type of tuples in an inductive style when writing trait
86-
implementations.
82+
## The `...T` Type Syntax
83+
This syntax would allow for expansion of tuple types into a list of types.
84+
For example, `(A, B, C)` could be represented as `(A, ...(B, C))` or
85+
`(...(A, B), C)`. This allows users to express type lists of varying arity.
8786

88-
## The `(head, ...tail)` Pattern-Matching Syntax
87+
## The `...x` Pattern-Matching Syntax
8988
This syntax allows for splitting apart the head and tail of a tuple. For
9089
example, `let (head, ...tail) = (1, 2, 3);` moves the head value, `1`, into
91-
`head`, and the tail value, `(2, 3)`, into `tail`.
90+
`head`, and the tail value, `(2, 3)`, into `tail`. Similarly, the last element
91+
of a tuple could be matched out using `let (...front, last) = (1, 2, 3);`.
9292

93-
## The `(head, ...tail)` Joining Syntax
93+
## The `...x` Joining Syntax
9494
This syntax allows pushing an element onto a tuple. It is the natural inverse
9595
of the pattern-matching operation above. For example,
9696
`let tuple = (1, ...(2, 3));` would result in `tuple` having a value of
@@ -146,6 +146,11 @@ a base case, `()`, and a recursive/inductive case: `(Head, ...Tail)`. Any tuple
146146
can be thought of in this way
147147
(for example, `(A, B, C)` is equivalent to `(A, ...(B, ...(C, ...())))`).
148148

149+
When teaching this new syntax, it is important to note that the proposed system
150+
allows for more complicated matching than traditional `Cons`-lists. For example,
151+
it is possible to match on `(...Front, Last)` in addition to the familiar
152+
`(Head, ...Tail)`-style matching.
153+
149154
The exact mechanisms used to teach this should be determined after getting more
150155
experience with how Rustaceans learn. After all, Rust users are a diverse crowd,
151156
so the "best" way to teach one person might not work as well for another. There
@@ -193,6 +198,7 @@ unified `Tuple`.
193198

194199
# Unresolved questions
195200
[unresolved]: #unresolved-questions
201+
196202
-It might be useful in the future to expand on the locations where `...Type`
197203
can be used. Potential extensions to this RFC could allow `...Type` in
198204
non-tuple generics or in function argument types, like

0 commit comments

Comments
 (0)