@@ -79,18 +79,18 @@ implementations of `Tuple` will be added. This enables an increased level of
79
79
negative reasoning making it easier to write blanket implementations of traits
80
80
for tuples.
81
81
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.
87
86
88
- ## The ` (head, ...tail) ` Pattern-Matching Syntax
87
+ ## The ` ...x ` Pattern-Matching Syntax
89
88
This syntax allows for splitting apart the head and tail of a tuple. For
90
89
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); ` .
92
92
93
- ## The ` (head, ...tail) ` Joining Syntax
93
+ ## The ` ...x ` Joining Syntax
94
94
This syntax allows pushing an element onto a tuple. It is the natural inverse
95
95
of the pattern-matching operation above. For example,
96
96
` 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
146
146
can be thought of in this way
147
147
(for example, ` (A, B, C) ` is equivalent to ` (A, ...(B, ...(C, ...()))) ` ).
148
148
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
+
149
154
The exact mechanisms used to teach this should be determined after getting more
150
155
experience with how Rustaceans learn. After all, Rust users are a diverse crowd,
151
156
so the "best" way to teach one person might not work as well for another. There
@@ -193,6 +198,7 @@ unified `Tuple`.
193
198
194
199
# Unresolved questions
195
200
[ unresolved ] : #unresolved-questions
201
+
196
202
-It might be useful in the future to expand on the locations where ` ...Type `
197
203
can be used. Potential extensions to this RFC could allow ` ...Type ` in
198
204
non-tuple generics or in function argument types, like
0 commit comments