# Generics which are private to a type

**URL:** <https://forums.swift.org/t/generics-which-are-private-to-a-type/42537>\
**Category:** Discussion\
**Created:** [December 5, 2020, 8:34am UTC](https://forums.swift.org/t/generics-which-are-private-to-a-type/42537 "2020-12-05T08:34:24Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Lantua](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lantua/32/8868_2.png) [@Lantua](https://forums.swift.org/u/Lantua)\
**Post date:** [December 6, 2020, 2:32am UTC](https://forums.swift.org/t/generics-which-are-private-to-a-type/42537/3 "2020-12-06T02:32:06Z")

</div>

> [@Jon\_Hull](#):
>
> It is a shame that you can't have collections over C with different T's, since T is irrelevant to the interface of C.

I'm not sure what you're trying to achieve, but `C<T1>` and `C<T2>` have different memory layouts. It's not possible to just lay them bare in an array, and you can not write

```swift
let a = Wrapper(proto1) // type Wrapper<X>

// This *should* work from type system perspective,
// but cannot because `Wrapper<T1, X>` and `Wrapper<T2, X>`
// have different layout.
a = Wrapper(proto2) // type Wrapper<X>

```

That's essentially why you need existential to _box_ `T` or even `C<T>`. _Hiding information_ about `T` doesn't change that fact unless you include type erasure or some kind of boxing mechanism into that _hiding_ process.

If _boxing_ is part of your plan, there are some idea floating around about synthesizing type erasure. You can probably search this forum for that. There's also this thread ([Lifting the "Self or associated type" constraint on existentials](https://forums.swift.org/t/lifting-the-self-or-associated-type-constraint-on-existentials/18025)) that you may be interested in. It's already 2-yr old though, so best not to bump it.

---

_[View the full topic](https://forums.swift.org/t/generics-which-are-private-to-a-type/42537)._
