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
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`.
369
369
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:
371
371
372
372
```swift
373
373
func variadic<each S:Sequence, T>(_: repeateach S) where (each S).Element==T {}
374
374
```
375
375
376
-
This is called a _concrete same-element requirement_.
376
+
This is called a _same-element requirement_.
377
377
378
378
A valid substitution for the above might replace `S` with `{Array<Int>, Set<Int>}`, and `T` with `Int`.
379
379
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:
381
380
382
-
```swift
383
-
func variadic<each S:Sequence, each T>(_: repeateach S) where (each S).Element==eachT {}
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 whereeach 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.
391
382
392
383
```swift
393
384
func variadic<each S:Sequence, each T>(_: repeateach S) where (each S).Element==Array<each T> {}
394
385
```
395
386
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>(_: repeateach S, _: repeateach 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_.
407
388
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`.
409
390
410
391
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.
0 commit comments