# \[Pitch\] Parameter Packs

**URL:** <https://forums.swift.org/t/pitch-parameter-packs/60543>\
**Category:** Pitches\
**Tags:** generics, variadic-generics\
**Created:** [September 28, 2022, 3:53am UTC](https://forums.swift.org/t/pitch-parameter-packs/60543 "2022-09-28T03:53:51Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![filip-sakel](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/filip-sakel/32/8697_2.png) [@filip-sakel](https://forums.swift.org/u/filip-sakel)\
**Post date:** [September 29, 2022, 1:10pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/41 "2022-09-29T13:10:11Z")

</div>

> [@xwu](#):
>
> Suppose that's something like `each`

I think `each` would also be nicer for element-wise constraints. E.g.

```swift
<pack As, pack Bs>(
  a: each As, b: each Bs
) where each As.Element == each Bs.Element

```

---

<div class="post-metadata">

**Author:** ![Jumhyn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jumhyn/32/3891_2.png) [@Jumhyn](https://forums.swift.org/u/Jumhyn)\
**Post date:** [September 29, 2022, 1:20pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/42 "2022-09-29T13:20:50Z")

</div>

> [@hisekaldma](#):
>
> To my mind it’s the exact opposite: it’s super clear that `...` is the pluralization. `T…` means ”many T”. Spelling the type as a plural too means it’s double-pluralized, which is extremely confusing.

Yeah, I think Holly’s post does a good job of showing both sides of the coin and has left me feeling more conflicted than I was initially. Unfortunately I can’t think of a good way to handle the fact that plural/singular is clearly the more natural choice depending on the context in which you use the identifier, other than allowing users to introduce arbitrary synonyms for pack values/types, e.g.:

```swift
func f<Element(Elements)...>(element(elements): Element...) where Element: Comparable {
  for element in elements... { ... }
}

```

> [@hborla](#):
>
> For example, given the pack parameter `<S...>(sequence: S...)`, the pattern `sequence.count...` naturally reads to me as "get the count of every sequence in this pack", whereas `sequences.count...` looks like you're getting the count of the pack.

I wonder if what’s going wrong here isn’t that `sequences` is misnamed, but that the `.` here _looks like_ just a normal member access when it’s really a sort of projection operation over the pack.

I could imagine us requiring a different syntax here, so that rather than `sequences.count` you’d write `sequences->count` or something.

Of course, doing something specific for member accesses does nothing to address the fact that `sequences` is unusual _as an expression value_, not just as the base of a member access. I think this is a discomfort I have with the pattern expansion syntax as-proposed, beyond the use of `…`. Even if you know you’re dealing with a pack expansion plan ellipsis, it won’t necessarily be obvious _what_ is getting expanded because the pack looks like a normal identifier.

Perhaps that suggests something like the following would be good:

```swift
{sequences}.count...

```

This would make it clear that `sequences` is a pack we’re expanding rather than a normal expression value, and it would also make the pack easier to find inside a complex expansion pattern.

ETA: Since my phone insists on correcting `...` to a unicode ellipsis character, here's a proposal: `...` retains its current meaning an we use U+2026 `…` for variadic generics.

---

<div class="post-metadata">

**Author:** ![Gero](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gero/32/23571_2.png) [@Gero](https://forums.swift.org/u/Gero)\
**Post date:** [September 29, 2022, 1:49pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/43 "2022-09-29T13:49:41Z")

</div>

This is an interesting concept for sure and judging by the many comments already a welcomed one, but I have a very simple question about this:

> [@hborla](#):
>
> - If the type of a function parameter is a pack expansion type, the parameter must either be the final parameter in the function’s parameter list, or it must be followed by another parameter with a label.
> - [...]
> - If a pack expansion type appears inside of a function type’s parameter list; it must be the only pack expansion type in the function’s parameter list. (This rule is slightly different from that of pack expansion types in the parameter of a _function declaration_, because function _types_ cannot have argument labels.)

Very well possible I am missing something, but supposed we have such a function declaration along the first point:

```swift
func withTypePacks(label1 foo: T..., label2 bar: U...)

```

How can I define a property or local variable for it? Just via type inference? That would be a hard limitations I don't have for any other function. I mean, I can basically have a variable for a closure and usually _always_ assign it a function instead, correct?

```swift
func justOnePack(easy foo: T..., peasy bar: U) // for this I could do:

var localVariable: (T..., U) -> Void
localVariable = justOnePack(easy:peasy:)
localVariable(value1TypedT, value2TypedT, valueTypedU) // calling the closure

func withTypePacks(label1 foo: T..., label2 bar: U...) // legal function declaration according to bullet 1

var anotherVar: (T..., U...) -> Void // this is illegal according to the last bullet point, right?
anotherVar = withTypePacks(label1:label2:)
anotherVar(value1TypedT, value2TypedT, value1TypedU, value2TypedU) // but this should work, right?

```

I am sure I am just completely missing something here, but I am, apparently, blind. It would be a pretty big thing if all of a sudden there's such a distinction between closures and "proper" functions...

Edit: Just realizing it, I believe: Is the issue with the same type, i.e. if `T` and `U` would be the same? So just the following would be illegal:

```swift
func withTwoSameTypePacks(label1 foo: T..., label2: bar: T...)
// callable as:
withTwoSameTypePacks(label1: value1TypedT, value2TypedT, label2: value3TypedT, value4TypedT)
// in the functions body foo would be the first two values, and bar the last two

var asVariable: (T..., T...) -> Void
asVariable = withTwoSameTypePacks(label1:label2:)
asVariable(value1TypedT, value2TypedT, value3TypedT, value4TypedT)
// how can the function figure out which values are in foo, which in bar?

```

I assume that's it, but I am inclined to then rather forbid defining functions with more than one identical type packs in general instead of basically disallowing them to be stored in variables until we maybe get labeled closure calls?

---

<div class="post-metadata">

**Author:** ![Jumhyn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jumhyn/32/3891_2.png) [@Jumhyn](https://forums.swift.org/u/Jumhyn)\
**Post date:** [September 29, 2022, 1:58pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/44 "2022-09-29T13:58:24Z")

</div>

> [@Gero](#):
>
> I am sure I am just completely missing something here, but I am, apparently, blind. It would be a pretty big thing if all of a sudden there's such a distinction between closures and "proper" functions...

There’s been some discussion of this issue [up-thread](https://forums.swift.org/t/pitch-parameter-packs/60543/19) (though no great solution offered).

---

<div class="post-metadata">

**Author:** ![Gero](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gero/32/23571_2.png) [@Gero](https://forums.swift.org/u/Gero)\
**Post date:** [September 29, 2022, 2:01pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/45 "2022-09-29T14:01:45Z")

</div>

Oh, thanks, and I apologize. I actually overlooked that... 😅  
I mean, I just got it, but as my above example illustrates this applies to the same type packs only, correct? (Obviously that can quickly become way more messy if generics are involved and ultimately the resolved concrete types turn out to be the same...)

---

<div class="post-metadata">

**Author:** ![Karl](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Karl](https://forums.swift.org/u/Karl)\
**Post date:** [September 29, 2022, 2:08pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/46 "2022-09-29T14:08:01Z")

</div>

It is also the case for all generic functions, whether it involves variadic generics or plain generics:

```swift
func someFunction<C>(_: C) where C: Collection { }

type(of: someFunction)
// error: generic parameter 'C' could not be inferred

let x = someFunction
// error: generic parameter 'C' could not be inferred

let y = someFunction<Array<Int>>
// error: cannot explicitly specialize a generic function

```

Generic closures are high on the list of things I'd like us to add to Swift.

---

<div class="post-metadata">

**Author:** ![John\_McCall](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/john_mccall/32/1351_2.png) [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Post date:** [September 29, 2022, 5:05pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/47 "2022-09-29T17:05:38Z")

</div>

There's an innate conflict here between the _declaration_ of a pack, where the name stands for a sequence and it feels right to pluralize it (e.g. `Widgets`), and the _uses_ of a pack, where the name is always part of an expansion and stands for one component and so feels like it ought to be singular (e.g. `Widget`). This is a place where experience with a similar feature (e.g. from C++) could potentially be very helpful; unfortunately, as someone with that experience, I can tell you that I've never found an appealing resolution to that conflict, so my experience is in fact not helpful at all.

Now, this conflict would be resolved if we allowed the use site to bind a different name to the pack element. I can think of a couple different syntaxes for that:

- `for A in Arguments { A? }`
- `each A in Arguments { A? }`
- ` Arguments.map { A in A? }`

I don't love any of them, though. And in context, I worry that people won't understand that this is an expansion, so maybe they also need a trailing `...`, which just makes the syntax worse. They're also a little awkward when it comes to expanding multiple packs in parallel — the first two, I can imagine something with parens, but for `.map` I really don't know.

Maybe the biggest problem is that this feels really heavyweight when you're just trying to expand the pack directly, which is very common. That's especially true in variadic generic functions, where we probably declare the type parameter pack `T` and then immediately turn around and declare a value parameter pack of type `T...`, or a single parameter of type `Stream<T...>`, or whatever. It's interesting to note that the naming issue disappears here, too: there's nothing misleading or confusing about just writing `Arguments...`. So if we _can_ settle on a binding/mapping expansion syntax, maybe we can hybridize that syntax with `...`, so that `...` when the operand is directly a pack reference means a direct pack expansion without any mapping, and otherwise you have to use the binding/mapping syntax.

(This would also eliminate the formal ambiguities with `...`, since you could only use it directly on pack references, which would otherwise be ill-formed. If you wanted to write a pack expansion of half-open ranges, you could just write `each lowerBound in args { lowerBound... }...`. It would still be _visually_ ambiguous, of course.)

This would also give us a syntax for the dreaded "type of pack expansion no longer refers to a pack" problem, e.g. the type of `collections.count...`, where every component is concretely an `Int` but the expression is still a pack expansion.

---

<div class="post-metadata">

**Author:** ![Tino](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tino/32/1073_2.png) [@Tino](https://forums.swift.org/u/Tino)\
**Post date:** [September 29, 2022, 5:24pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/48 "2022-09-29T17:24:53Z")

</div>

Sadly, to me this looks like yet another case where it is considered more important to integrate some new shiny feature as soon as possible instead of striving for the best long-term solution.  
Copying what C++ did might be cheap, but I don't think it's a good fit — and imo deciding about some smaller pieces like labels for generic parameters and value generics should happen before landing a huge change which could benefit from such preparation.

---

<div class="post-metadata">

**Author:** ![hborla](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hborla/32/27563_2.png) [@hborla](https://forums.swift.org/u/hborla)\
**Post date:** [September 29, 2022, 5:33pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/49 "2022-09-29T17:33:52Z")

</div>

> [@John\_McCall](#):
>
> This is a place where experience with a similar feature (e.g. from C++) could potentially be very helpful; unfortunately, as someone with that experience, I can tell you that I've never found an appealing resolution to that conflict, so my experience is in fact not helpful at all.

I have only used variadic generics in other languages for educational purposes, but when writing out the examples in Swift, I found my self almost always using the singular name for type parameter packs, and the plural name for value parameter packs. I think I gravitated toward using plural names for value packs because 1) I didn't think to write a separate argument label and wanted to use the plural name at the call-site, and 2) with iteration, you typically use the singular/plural names together, so it's hard to figure out what to call the local variable when you're iterating over a direct pack expansion, e.g. `for value in values...`. But otherwise, I have a much easier time understanding the code when patterns use the singular name.

---

<div class="post-metadata">

**Author:** ![hborla](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hborla/32/27563_2.png) [@hborla](https://forums.swift.org/u/hborla)\
**Post date:** [September 29, 2022, 5:48pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/50 "2022-09-29T17:48:30Z")

</div>

> [@Tino](#):
>
> Sadly, to me this looks like yet another case where it is considered more important to integrate some new shiny feature as soon as possible instead of striving for the best long-term solution.  
> Copying what C++ did might be cheap, but I don't think it's a good fit

There is a relatively extensive alternatives considered section as far as a first pitch goes, and we've been exploring those alternatives for over a year now. It's fine to leave a drive by comment that you don't like the design, but it sounds like you might have thoughts on what would be a better fit for Swift. If you do, that's great and I would appreciate elaboration.

> [@Tino](#):
>
> imo deciding about some smaller pieces like labels for generic parameters and value generics should happen before landing a huge change which could benefit from such preparation.

These features are both orthogonal to the fundamental model of abstracting over a variable number of type parameters.

---

<div class="post-metadata">

**Author:** ![Jumhyn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jumhyn/32/3891_2.png) [@Jumhyn](https://forums.swift.org/u/Jumhyn)\
**Post date:** [September 29, 2022, 6:15pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/51 "2022-09-29T18:15:40Z")

</div>

> [@John\_McCall](#):
>
> There's an innate conflict here between the _declaration_ of a pack, where the name stands for a sequence and it feels right to pluralize it (e.g. `Widgets`), and the _uses_ of a pack, where the name is always part of an expansion and stands for one component and so feels like it ought to be singular (e.g. `Widget`).

We could always introduce a language model into name lookup so that `Widgets...` would implicitly introduce the `Widget` name as well, and `Indices...` would properly singularize to `Index`. 🙂

> [@John\_McCall](#):
>
> Now, this conflict would be resolved if we allowed the use site to bind a different name to the pack element. I can think of a couple different syntaxes for that:
> 
> - `for A in Arguments { A? }`
> - `each A in Arguments { A? }`
> - ` Arguments.map { A in A? }`
> 
> I don't love any of them, though.

Yeah, I was thinking about something similar in an early variadic generics thread, though only as a tool for writing constraints:

> [@Pitching The Start of Variadic Generics](https://forums.swift.org/t/pitching-the-start-of-variadic-generics/51467/5):
>
> I could imagine us introducing, for instance, a new type of generic constraint that would allow us to supply a name for each element in a type sequence. Something like:
> 
> ```swift
> func allPresent<Haystacks..., Needles...>(haystacks: Haystacks..., needles: Elements...) -> Bool
> where forEach(Haystack in Haystacks, Needle in Needles, Haystack == Set<Needle>)
> 
> ```

I'm not totally sold either.

> [@John\_McCall](#):
>
> Maybe the biggest problem is that this feels really heavyweight when you're just trying to expand the pack directly, which is very common.

Yep, this is my feeling as well, and I wouldn't be opposed the type of regime you're proposing where we have a shorthand syntax for the simplest case and then fall back to a heavier syntax as soon as you want to do anything more complex. I think I'd still _prefer_ something that makes it clear in `elements...` that we're working with a pack rather than a range bound, but at least it doesn't have the issue of the pack reference being buried deep inside a complex expression.

> [@hborla](#):
>
> I have only used variadic generics in other languages for educational purposes, but when writing out the examples in Swift, I found my self almost always using the singular name for type parameter packs, and the plural name for value parameter packs.

I feel like we can only really resolve this with one of two things:

- Explicit pack syntax to make it visually obvious when you're referring to the full pack
- Explicit destructuring syntax that allows you to introduce a singular name

As you (and John) noted in your previous post(s), there's a fundamental conflict between different usages of a pack that make a single choice for singular or plural look silly in some contexts.

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [September 29, 2022, 7:00pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/52 "2022-09-29T19:00:22Z")

</div>

> [@Jumhyn](#):
>
> I feel like we can only really resolve this with one of two things:
> 
> - Explicit pack syntax to make it visually obvious when you're referring to the full pack
> - Explicit destructuring syntax that allows you to introduce a singular name
> 
> As you (and John) noted in your previous post(s), there's a fundamental conflict between different usages of a pack that make a single choice for singular or plural look silly in some contexts.

I think the silliness (totally agree with @hborla, by the way, about being drawn to the plural for values and the singular for types) is a symptom of the underlying cause where there are currently different usages sharing the same syntax, and perhaps @John_McCall's diagnosis is correct here:

> [@John\_McCall](#):
>
> So if we _can_ settle on a binding/mapping expansion syntax, maybe we can hybridize that syntax with `...`, so that `...` when the operand is directly a pack reference means a direct pack expansion without any mapping, and otherwise you have to use the binding/mapping syntax.

---

<div class="post-metadata">

**Author:** ![GreatApe](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/greatape/32/2640_2.png) [@GreatApe](https://forums.swift.org/u/GreatApe)\
**Post date:** [September 29, 2022, 7:16pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/53 "2022-09-29T19:16:07Z")

</div>

This feature has been at the top of many wish lists essentially since Swift was released, so I don't think that's a fair characterisation.

---

<div class="post-metadata">

**Author:** ![hborla](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hborla/32/27563_2.png) [@hborla](https://forums.swift.org/u/hborla)\
**Post date:** [September 29, 2022, 7:55pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/54 "2022-09-29T19:55:59Z")

</div>

> [@xwu](#):
>
> I think the silliness (totally agree with @hborla, by the way, about being drawn to the plural for values and the singular for types) is a symptom of the underlying cause where there are currently different usages sharing the same syntax, and perhaps @John_McCall's diagnosis is correct here:
> 
> > [@John\_McCall](#):
> >
> > So if we _can_ settle on a binding/mapping expansion syntax, maybe we can hybridize that syntax with `...`, so that `...` when the operand is directly a pack reference means a direct pack expansion without any mapping, and otherwise you have to use the binding/mapping syntax.

I think I disagree that direct expansion vs expansion+map should have a separate syntax/mental model. The mental model that I find intuitive for an expansion of length `N` is "repeat this pattern `N` times". That mental model works for both plain pack expansions and an expansion where the pack is wrapped in some other type or expression.

Take this [WeatherKit API](https://developer.apple.com/documentation/weatherkit/weatherservice/weather(for:including:_:)) as an example, written using parameter packs (under this pitch) instead of 7 overloads. The developer documentation uses `dataSet1`, `dataSet2`, etc, as the parameter names in the overloads, so in this case `dataSet` describes a single value of `WeatherQuery`:

```swift
func weather<T...>(
    for location: CLLocation,
    including dataSet: WeatherQuery<T>...) async throws -> (T...)
)

```

This makes sense to me as "repeat the `dataSet: WeatherQuery<T>` parameter `N` times". This, on the other hand, is way harder for me to understand:

```swift
func weather<Ts...>(
    for location: CLLocation,
    including dataSets: for T in Ts { WeatherQuery<T> }) async throws -> (Ts...)
)

```

I don't know how to explain this. It's hard to describe that `dataSets` is a parameter pack, i.e. separate parameters, repeated. I also don't know that I can get behind putting a `for-in` syntax or any other mapping syntax into a parameter list 😵‍💫

I think the parameter label issue I brought up can be solved with an API design guideline that for function parameter packs, you should use a separate argument label from the name of the pack. That really only leaves `for-in` loops as the problem:

```swift
for data in dataSet... {} // ???

```

`for-in` loops are kinda hard to think about under the repetition pattern model. I think what you really want is just a body of code that is repeated for each value in the expanded pattern. Maybe that suggests we should find a different way to express iteration, or maybe we should just let you call the binding the same name as the pack if you're expanding a pack directly.

---

<div class="post-metadata">

**Author:** ![Jumhyn](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jumhyn/32/3891_2.png) [@Jumhyn](https://forums.swift.org/u/Jumhyn)\
**Post date:** [September 29, 2022, 8:20pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/55 "2022-09-29T20:20:20Z")

</div>

> [@hborla](#):
>
> `for-in` loops are kinda hard to think about under the repetition pattern model. I think what you really want is just a body of code that is repeated for each value in the expanded pattern. Maybe that suggests we should find a different way to express iteration, or maybe we should just let you call the binding the same name as the pack if you're expanding a pack directly.

We could also take the position that expansion patterns are permitted to consist of multiple statements, so that you could write:

```swift
  {
    result = result && array.isEmpty
    doSomething(with: result)
  }...

```

or, if we feel that we really need some _introduction_ of the expansion maybe you can expand a value pack _into_ a statement block:

```swift
array... {
    result = result && array.isEmpty // within this block, `array` refers to a single element of the pack
    doSomething(with: result)
}

```

or maybe somehow extend `do`?

```swift
do... {
    result = result && array.isEmpty
    doSomething(with: result)
}

```

of course, all of these preclude using `array` _as a pack_ within the repeated block, so you couldn't do something like:

```swift
for element in elements... {
  print(element, bestMatchNotEqual(to: element, from: elements))
}

```

I can't really think of a concrete situation where this would be useful, but the `for`-`in` at least makes it possible to do, even if naming the pack/element is a little funky.

---

<div class="post-metadata">

**Author:** ![Tino](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tino/32/1073_2.png) [@Tino](https://forums.swift.org/u/Tino)\
**Post date:** [September 29, 2022, 8:35pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/56 "2022-09-29T20:35:30Z")

</div>

> [@GreatApe](#):
>
> This feature has been at the top of many wish lists

This motivation is exactly what I consider to be wrong: Features should be added when they fit into the big picture, and not in the by their rank in some wishlist.  
Returning to an old comparison ([[planning] [discussion] Schedule for return of closure parameter labels (+ world domination ramble) - #7 by Chris\_Lattner](https://forums.swift.org/t/planning-discussion-schedule-for-return-of-closure-parameter-labels-world-domination-ramble/6448/7)):  
You usually really want a roof when you build a house, but still you finish the walls first.

---

<div class="post-metadata">

**Author:** ![filip-sakel](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/filip-sakel/32/8697_2.png) [@filip-sakel](https://forums.swift.org/u/filip-sakel)\
**Post date:** [September 29, 2022, 9:04pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/57 "2022-09-29T21:04:03Z")

</div>

> [@hborla](#):
>
> `for-in` loops are kinda hard to think about under the repetition pattern model. I think what you really want is just a body of code that is repeated for each value in the expanded pattern. Maybe that suggests we should find a different way to express iteration, or maybe we should just let you call the binding the same name as the pack if you're expanding a pack directly.

I don’t necessarily agree with this. The element type of packs could be considered the union of all types making up the pack. Since the types making up the pack are unknown in the generic context, they could be opaque types that expose the constraints placed on the parameter pack’s elements. In pseudo Swift

```swift
typealias H = (Bool, Int, String)

H.Element.self // (Bool | Int | String).self

func hello<pack Values>(values: expand Values) {
  (expand Values).Element.self // some Any
}

```

To be clear, I’m not proposing a union feature, just exploring a conceptual model for the type of pack elements.

---

<div class="post-metadata">

**Author:** ![John\_McCall](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/john_mccall/32/1351_2.png) [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Post date:** [September 29, 2022, 9:12pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/58 "2022-09-29T21:12:47Z")

</div>

Picking an opaque type that maximally generalizes a bunch of concrete types is actually a very difficult problem that’s prone to instability (and thus source incompatibility) around API changes.

Doing it for an abstract pack is stabilized by the generic signature the user specified.

---

<div class="post-metadata">

**Author:** ![filip-sakel](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/filip-sakel/32/8697_2.png) [@filip-sakel](https://forums.swift.org/u/filip-sakel)\
**Post date:** [September 29, 2022, 9:21pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/59 "2022-09-29T21:21:35Z")

</div>

The proposal references zip, which already has variants (zip2, zip3, etc.) in frameworks like Combine. Builder APIs, like SwiftUI has already demonstrated the need for variadic generics. Multi-dimensional arrays would also be a nice performance improvement compared to just nesting arrays. Further, math frameworks, especially those used in ML would significantly benefit from variadic genetics (and integer generic parameters but that’s a different discussion). Overall, I think there are already several examples of how parameter packs will be useful.

> [@John\_McCall](#):
>
> Doing it for an abstract pack is stabilized by the generic signature the user specified.

Yeah, I was mostly referring to the generic case. I think it’s fair to make the hypothetical Element type of a concrete tuple unutterable or, at least, `some Any`. Making it unutterable would have the benefit of the user explicitly specifying which constraints they want to enforce, by writing something like the following (which is admittedly a mouthful).

```swift
(Int, String) as (expand some pack Hashable)

```

---

<div class="post-metadata">

**Author:** ![GreatApe](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/greatape/32/2640_2.png) [@GreatApe](https://forums.swift.org/u/GreatApe)\
**Post date:** [September 29, 2022, 10:04pm UTC](https://forums.swift.org/t/pitch-parameter-packs/60543/60 "2022-09-29T22:04:49Z")

</div>

My point was that it can hardly be claimed that this feature has been rushed. But concretely then, why is now not the right time, what is missing that needs to precede this, that this builds on?

[Previous page](https://forums.swift.org/t/pitch-parameter-packs/60543.md?page=2)

[Next page](https://forums.swift.org/t/pitch-parameter-packs/60543.md?page=4)
