Skip to content

Commit 6c2cd8f

Browse files
committed
Review feedback
1 parent 41bc134 commit 6c2cd8f

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

TSPL.docc/LanguageGuide/Generics.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ even though the doubling operation could really apply
18891889
to any number of arguments.
18901890

18911891
Other approaches that also have drawbacks
1892-
include taking the arguments an array or a variadic parameter,
1892+
include taking the arguments as an array or a variadic parameter,
18931893
which requires all arguments to be the same type,
18941894
or using `Any` which erases type information.
18951895

@@ -1905,12 +1905,11 @@ func double<each T: Numeric>(_ value: repeat each T) -> (repeat each T) {
19051905
}
19061906
```
19071907

1908-
In the code above, `Element` is a generic type parameter.
1909-
It's marked `each Element`,
1910-
indicating that it's a type-parameter pack.
1908+
In the code above, `each T` is declared in a generic parameter list.
1909+
It's marked with `each`, indicating that it's a type parameter pack.
19111910
In contrast to a generic type parameter,
19121911
which serves as a placeholder for a single type,
1913-
a type-parameter pack is a placeholder for multiple types.
1912+
a type parameter pack is a placeholder for multiple types.
19141913
The ability to have `T` contain a varying number of types
19151914
is what allows this version of `double(_:)`
19161915
to take any number of parameters
@@ -1933,7 +1932,7 @@ extension Numeric {
19331932
}
19341933

19351934
let numbers = [12, 0.5, 8 as Int8]
1936-
let doubledNumbers = double(numbers)
1935+
let doubledNumbers = doubled(numbers)
19371936
```
19381937

19391938
The value of `doubledNumbers` is `(24, 1.0, 16)`,
@@ -1980,7 +1979,7 @@ How do you create a parameter pack?
19801979
and in function argument lists.
19811980

19821981
```swift
1983-
func f<each T>(_ t: repeat each T) -> repeat each T
1982+
func f<each T>(_ t: repeat each T) -> (repeat each T)
19841983
```
19851984

19861985
- The expansion pattern is repeated for every element in the given type pack
@@ -2035,8 +2034,8 @@ How do you constrain the types in a parameter pack?
20352034
- In the more complex case,
20362035
use `repeat each T ` in a trailing `where` clause.
20372036

2038-
- You must restrict the types that appear in a type-parameter pack;
2039-
conformance requirements don't implicitly propagate.
2037+
- You must restrict the types that appear in a type parameter pack
2038+
if its expansion will be used as a restricted generic type parameter.
20402039
For example, given `each T: Hashable` writing `repeat Set<each T>` works,
20412040
but it doesn't work with just `each T`
20422041
because `Set` requires `T` to be hashable but the pack doesn't.
@@ -2062,7 +2061,7 @@ How do you access the values of a parameter pack?
20622061
```
20632062

20642063
- The result (and its type) of expanding a parameter pack
2065-
vary depending on the number of elements in the pack.
2064+
within a tuple vary depending on the number of elements in the pack.
20662065
Zero-element packs produce `()`,
20672066
single-element packs produce a simple type,
20682067
and multi-element packs produce a tuple type.
@@ -2073,7 +2072,7 @@ How do you access the values of a parameter pack?
20732072

20742073
For example,
20752074
`repeat (each T, Int)` is different from `(repeat each T, Int)`.
2076-
The former makes multiple tuple `(T1, Int) ... (Tn, Int)`,
2075+
The former makes multiple tuples `(T1, Int) ... (Tn, Int)`,
20772076
expanding `T` and adding `Int` to each tuple.
20782077
The latter makes one tuple, `(T1, ..., Tn, Int)`.
20792078
Other code can come between `repeat` and `each` ---

TSPL.docc/ReferenceManual/Expressions.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,7 @@ XXX OUTLINE:
14891489
+ in a tuple, producing tuple elements
14901490
+ as a statement, including at top level, repeating the statement's expression
14911491
+ but not in a function call, producing arguments
1492+
+ in a `for`-`each` loop
14921493

14931494
- The *repetition pattern* is repeated once for each type in the pack
14941495

@@ -1497,15 +1498,15 @@ XXX OUTLINE:
14971498
the `repeat` operator must appear first.
14981499
(So `repeat try each foo` or `repeat each try foo`)
14991500

1500-
- All of the `each` expressions in a parameter-pack expression
1501+
- All of the `each` expressions in a pattern expression
15011502
must expand packs that have the same number of types.
15021503

15031504
- In a function declaration,
15041505
an argument whose type is a parameter-pack expansion type
15051506
must be the last parameter
15061507
or the parameter after it must have a label.
15071508

1508-
- It's valid for a pack expression contain no elements,
1509+
- It's valid for a pack expression to contain no elements,
15091510
in which case the parameter-pack expansion expression isn't evaluated at all (zero times)
15101511

15111512
<!--

TSPL.docc/ReferenceManual/Types.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -949,16 +949,18 @@ https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-an
949949
>
950950
> *boxed-protocol-type***`any`** *type*
951951
952-
## Type-Parameter Pack
952+
## Type Parameter Pack
953953

954954
XXX OUTLINE:
955955

956-
- `each T` creates a type-parameter pack
956+
- `each T` creates a type parameter pack
957957
when it appears in a generic parameter clause,
958958
or indicates which pack should be expanded
959959
when it appears in a `repeat` expression
960960

961-
- `repeat T` expands the type-parameter pack
961+
- `repeat P`, where `P` captures at least one type
962+
parameter pack, expands it into a list of types
963+
or values
962964

963965
- Packs are never nested; expansion implies flattening
964966

@@ -967,16 +969,20 @@ XXX OUTLINE:
967969

968970
- It's valid for a type pack to contain no elements.
969971

970-
- list of places where type-parameter pack can appear:
972+
- list of places where type parameter pack can appear:
971973

972974
+ generic type parameter list
973975
+ as an argument to a generic type parameter
976+
+ tuple element
977+
+ function type parameter list
974978

975979
> Grammar of a type-parameter pack:
976980
>
977981
> *type-parameter-pack***`each`** *type*
978982
>
979-
> *type-parameter-pack-expansion***`repeat`** *type*
983+
> *type-parameter-pack-expansion***`repeat`** *pattern-type*
984+
>
985+
> *pattern-type* -> *type*
980986
981987
<!--
982988
The grammar above overproduces:

0 commit comments

Comments
 (0)