Skip to content

Commit 967688d

Browse files
committed
Simplify the description of same-type requirements involving parameter packs.
1 parent 38c3871 commit 967688d

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

proposals/NNNN-parameter-packs.md

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -365,47 +365,28 @@ All existing kinds of generic requirements generalize to type parameter packs. S
365365
func variadic<each S>(_: repeat each S) where each S: Sequence { ... }
366366
```
367367

368-
A valid substitution for the above might replace `S` with `{Array<Int>, Set<String>}`.
368+
A valid substitution for the above might replace `S` with `{Array<Int>, Set<String>}`. Expanding the substitution into the requirement `each S: Sequence` conceptually produces the following conformance requirements: `Array<Int>: Sequence, Set<String>: Sequence`.
369369

370-
2. A same-type requirement where one side is a type parameter pack and the other type is a concrete type that does not capture any type parameter packs is interpreted as constraining each element of the replacement type pack to _the same_ concrete type:
370+
2. A same-type requirement where one side is a type parameter pack and the other type is a scalar type that does not capture any type parameter packs is interpreted as constraining each element of the replacement type pack to _the same_ scalar type:
371371

372372
```swift
373373
func variadic<each S: Sequence, T>(_: repeat each S) where (each S).Element == T {}
374374
```
375375

376-
This is called a _concrete same-element requirement_.
376+
This is called a _same-element requirement_.
377377

378378
A valid substitution for the above might replace `S` with `{Array<Int>, Set<Int>}`, and `T` with `Int`.
379379

380-
3. A same-type requirement where one side is a type parameter pack and the other type is a scalar type parameter is interpreted as constraining each element of the replacement type pack to the type parameter:
381380

382-
```swift
383-
func variadic<each S: Sequence, each T>(_: repeat each S) where (each S).Element == each T {}
384-
```
385-
386-
This is called an _abstract same-element requirement_.
387-
388-
A valid substitution for the above might replace `S` with `{Array<Int>, Set<String>}`, and `T` with `{Int, String}`.
389-
390-
4. A same-type requirement where one side is a type parameter pack and the other side is a concrete type capturing at least one type parameter pack is interpreted as expanding the concrete type and constraining each element of the replacement type pack to the concrete element type:
381+
3. A same-type requirement where each side is a pattern type that captures at least one type parameter pack is interpreted as expanding the type packs on each side of the requirement, equating each element pair-wise.
391382

392383
```swift
393384
func variadic<each S: Sequence, each T>(_: repeat each S) where (each S).Element == Array<each T> {}
394385
```
395386

396-
This is called a _concrete same-type pack requirement_.
397-
398-
A valid substitution for the above might replace `S` with `{Array<Array<Int>>, Set<Array<String>>}`, and `T` with `{Int, String}`.
399-
400-
5. A same-type requirement where both sides are type parameter packs constrains the elements of the replacement type pack element-wise:
401-
402-
```swift
403-
func append<each S: Sequence, each T: Sequence>(_: repeat each S, _: repeat each T) where (each T).Element == (each S).Element {}
404-
```
405-
406-
This is called an _abstract same-type pack requirement_.
387+
This is called a _same-type-pack requirement_.
407388

408-
A valid substitution for the above would replace `S` with `{Array<Int>, Set<String>}`, and `T` with `{Set<Int>, Array<String>}`.
389+
A valid substitution for the above might replace `S` with `{Array<Array<Int>>, Set<Array<String>>}`, and `T` with `{Int, String}`. Expanding `(each S).Element == Array<each T>` will produce the following list of same-type requirements: `Array<Array<Int>.Element == Array<Int>, Set<Array<String>>.Element == String`.
409390

410391
There is an additional kind of requirement called a _same-shape requirement_. There is no surface syntax for spelling a same-shape requirement; they are always inferred, as described in the next section.
411392

0 commit comments

Comments
 (0)