You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 'pairs' is '(Pair(1, true), Pair("hello", 2.0))'
124
124
```
125
125
126
-
The `makrPairs` function declares two type parameter packs, `First` and `Second`. The value parameter packs `first` and `second` have the pack expansion types `repeat each First` and `repeat each Second`, respectively. The return type `(repeat Pair<each First, each Second>)` is a tuple type where each element is a `Pair` of elements from the `First` and `Second` parameter packs at the given tuple position.
126
+
The `makePairs` function declares two type parameter packs, `First` and `Second`. The value parameter packs `first` and `second` have the pack expansion types `repeat each First` and `repeat each Second`, respectively. The return type `(repeat Pair<each First, each Second>)` is a tuple type where each element is a `Pair` of elements from the `First` and `Second` parameter packs at the given tuple position.
127
127
128
128
Inside the body of `makePairs()`, `repeat Pair(each first, each second)` is a pack expansion expression referencing the value parameter packs `first` and `second`.
129
129
130
-
The call to `makrPairs()` substitutes the type pack `{Int, Bool}` for `First`, and the type pack `{String, Double}` for `Second`. These substitutions are deduced by the _type matching rules_, described below. The function is called with four arguments; `first` is the value pack `{1, "hello"}`, and `second` is the value pack `{true, 2.0}`.
130
+
The call to `makePairs()` substitutes the type pack `{Int, Bool}` for `First`, and the type pack `{String, Double}` for `Second`. These substitutions are deduced by the _type matching rules_, described below. The function is called with four arguments; `first` is the value pack `{1, "hello"}`, and `second` is the value pack `{true, 2.0}`.
131
131
132
132
The substituted return type is the tuple type with two elements `(Pair<Int, Bool>, Pair<String, Double>)`, and the returned value is the tuple value with two elements `(Pair(1, true), Pair("hello", 2.0))`.
133
133
@@ -148,7 +148,7 @@ When referenced from type context, this identifier resolves to a _type parameter
148
148
* The base type of a member type parameter pack, which is again subject to these rules
149
149
* The pattern type of a pack expansion type, where it stands for the corresponding scalar element type
150
150
* The pattern expression of a pack expansion expression, where it stands for the metatype of the corresponding scalar element type and can be used like any other scalar metatype, e.g. to call a static method, call an initializer, or reify the metatype value
151
-
* The subject type of a conformance, superclass, layout or same-type requirement
151
+
* The subject type of a conformance, superclass, layout, or same-type requirement
152
152
* The constraint type of a same-type requirement
153
153
154
154
### Pack expansion type
@@ -388,7 +388,7 @@ All existing kinds of generic requirements generalize to type parameter packs. S
388
388
389
389
A valid substitution for the above might replace `S` with `{Array<Int>, Set<String>}`, and `T` with `{Int, String}`.
390
390
391
-
3. 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:
391
+
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:
392
392
393
393
```swift
394
394
func variadic<each S:Sequence, each T>(_: repeateach S) where (each S).Element==Array<each T> {}
@@ -398,7 +398,7 @@ All existing kinds of generic requirements generalize to type parameter packs. S
398
398
399
399
A valid substitution for the above might replace `S` with `{Array<Array<Int>>, Set<Array<String>>}`, and `T` with `{Int, String}`.
400
400
401
-
3. A same-type requirement where both sides are type parameter packs constrains the elements of the replacement type pack element-wise:
401
+
5. A same-type requirement where both sides are type parameter packs constrains the elements of the replacement type pack element-wise:
402
402
403
403
```swift
404
404
func append<each S:Sequence, each T:Sequence>(_: repeateach S, _: repeateach T) where (each T).Element== (each S).Element {}
@@ -463,7 +463,7 @@ The type annotation of `tup` contains a pack expansion type `repeat (each T, eac
463
463
464
464
#### Open questions
465
465
466
-
While type packs cannot be written directly, a requirement where both sides are concrete types is desugared using the type matching algorithm, therefore it will be possible to write down a requirement that constraints a type parameter pack to a concrete type pack, unless some kind of restriction is imposed:
466
+
While type packs cannot be written directly, a requirement where both sides are concrete types is desugared using the type matching algorithm, therefore it will be possible to write down a requirement that constrains a type parameter pack to a concrete type pack, unless some kind of restriction is imposed:
0 commit comments