# Variadic Generics

**URL:** <https://forums.swift.org/t/variadic-generics/54511>\
**Category:** Pitches\
**Tags:** generics\
**Created:** [January 8, 2022, 5:38am UTC](https://forums.swift.org/t/variadic-generics/54511 "2022-01-08T05:38:55Z")\
**Posts on this page:** 1\
**Showing post:** 67

<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:** [January 29, 2022, 12:37am UTC](https://forums.swift.org/t/variadic-generics/54511/67 "2022-01-29T00:37:51Z")

</div>

> [@mklbtz](#):
>
> Maybe, in "code", documentation, warnings, etc. it would be appear as `any Whatever` , but _in implementation_ it's not _actually_ a sequence existential values. After all, the compiler would be optimizing away all that loop-like code since it knows the number of elements statically.

Right - it couldn't be an opaque type, because opaque types are, well, opaque "non-names" for a single underlying type.

But I do think there is significant overlap between existentials (and especially collections of existentials) and variadic generics, and the language is currently not well-equipped to deal with either of them comfortably because we don't have a concept of introducing new generic type parameters in the middle of a function. That's why, in the previous thread, I suggested that adding this would be a good step towards variadic generics:

> [@Pitching The Start of Variadic Generics](https://forums.swift.org/t/pitching-the-start-of-variadic-generics/51467/70):
>
> One thing that might be useful as a step towards variadic generics is introducing local generic parameters. For example, as @xAlien95 pointed out: func debugPrint\<T...\>(\_ items: T...) where T: CustomDebugStringConvertible { for (item: T) in items { // \<--- Here stdout.write(item.debugDescription) } } The T on the marked line is actually a new, local generic parameter which overrides the name T... in the function declaration. Actually, the T on that line refers to a different typ…

So I think it would be reasonable for the element type to be an existential, which the optimiser could then resolve during generic specialisation.

Also, I don't think it's true that the compiler always statically knows the number of elements. You can have unspecialised generic types today, and presumably variadic generic types may also be unspecialised in some circumstances.

---

_[View the full topic](https://forums.swift.org/t/variadic-generics/54511)._
