Skip to content

Commit d3043f8

Browse files
committed
Move local value packs and add explicit pack syntax to future directions.
1 parent 5940dc2 commit d3043f8

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

proposals/NNNN-parameter-packs.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
- [Same-shape requirements](#same-shape-requirements)
2828
- [Restrictions on same-shape requirements](#restrictions-on-same-shape-requirements)
2929
- [Value parameter packs](#value-parameter-packs)
30-
- [Local value packs](#local-value-packs)
3130
- [Effect on ABI stability](#effect-on-abi-stability)
3231
- [Alternatives considered](#alternatives-considered)
3332
- [Modeling packs as tuples with abstract elements](#modeling-packs-as-tuples-with-abstract-elements)
@@ -37,6 +36,8 @@
3736
- [Magic builtin `map` method](#magic-builtin-map-method)
3837
- [Future directions](#future-directions)
3938
- [Variadic generic types](#variadic-generic-types)
39+
- [Local value packs](#local-value-packs)
40+
- [Explicit type pack syntax](#explicit-type-pack-syntax)
4041
- [Pack iteration](#pack-iteration)
4142
- [Pack element projection](#pack-element-projection)
4243
- [Dynamic pack indexing with `Int`](#dynamic-pack-indexing-with-int)
@@ -553,18 +554,6 @@ func forward<each U>(u: repeat each U) {
553554
}
554555
```
555556

556-
### Local value packs
557-
558-
The notion of a value parameter pack readily generalizes to a local variable of pack expansion type, for example:
559-
560-
```swift
561-
func variadic<each T>(t: repeat each T) {
562-
let tt: repeat each T = repeat each t
563-
}
564-
```
565-
566-
References to `tt` have the same semantics as references to `t`, and must only appear inside other pack expansion expressions.
567-
568557
## Effect on ABI stability
569558

570559
This is still an area of open discussion, but we anticipate that generic functions with type parameter packs will not require runtime support, and thus will backward deploy. As work proceeds on the implementation, the above is subject to change.
@@ -670,6 +659,28 @@ The downsides of a magic `map` method are:
670659

671660
This proposal only supports type parameter packs on functions. A complementary proposal will describe type parameter packs on generic structs, enums and classes.
672661

662+
### Local value packs
663+
664+
This proposal only supports value packs for function parameters. The notion of a value parameter pack readily generalizes to a local variable of pack expansion type, for example:
665+
666+
```swift
667+
func variadic<each T>(t: repeat each T) {
668+
let tt: repeat each T = repeat each t
669+
}
670+
```
671+
672+
References to `tt` have the same semantics as references to `t`, and must only appear inside other pack expansion expressions.
673+
674+
### Explicit type pack syntax
675+
676+
In this proposal, type packs do not have an explicit syntax, and a type pack is always inferred through the type matching rules. However, we could explore adding an explicit pack syntax in the future:
677+
678+
```swift
679+
struct Variadic<each T> {}
680+
681+
extension Variadic where each T == {Int, String} {} // {Int, String} is a concrete pack
682+
```
683+
673684
### Pack iteration
674685

675686
All list operations can be expressed using pack expansion expressions by factoring code involving statements into a function or closure. However, this approach does not allow for short-circuiting, because the pattern expression will always be evaluated once for every element in the pack. Further, requiring a function or closure for code involving statements is unnatural. Allowing `for-in` loops to iterate over packs solves both of these problems.

0 commit comments

Comments
 (0)