# Introduce Any\<P\> as a better way of writing existentials

**URL:** <https://forums.swift.org/t/introduce-any-p-as-a-better-way-of-writing-existentials/39823>\
**Category:** Pitches\
**Created:** [August 29, 2020, 5:46am UTC](https://forums.swift.org/t/introduce-any-p-as-a-better-way-of-writing-existentials/39823 "2020-08-29T05:46:04Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![JoeyKL](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joeykl/32/3140_2.png) [@JoeyKL](https://forums.swift.org/u/JoeyKL)\
**Post date:** [August 29, 2020, 3:22pm UTC](https://forums.swift.org/t/introduce-any-p-as-a-better-way-of-writing-existentials/39823/17 "2020-08-29T15:22:28Z")

</div>

> [@bjhomer](#):
>
> ```swift
> protocol Animal {}
> struct Cat: Animal {}
> struct Dog: Animal {}
> 
> // A variable of type 'Animal' is an existential; it can hold *any* Animal
> var anyAnimal: Animal
> anyAnimal = Cat()
> anyAnimal = Dog()
> 
> func takeASpecificAnimal<T: Animal>(_ animal: T) {}
> 
> // error: value of protocol type 'Animal' cannot conform to 'Animal'; only struct/enum/class types can conform to protocols
> takeASpecificAnimal(anyAnimal)
> 
> ```

To me, the most straightforward solution here is to allow Animal to be a concrete type conforming to itself when this wouldn't cause any problems, i.e. when it doesn't have static, init, Self, or associatedtype requirements (the latter two cases already disallowed). We could allow protocols to be valid types only when these aren't present, and require `Any<P>` otherwise.

I picked projects at random from the [Source Compatibility Suite](https://swift.org/source-compatibility/#current-list-of-projects) and looked at the protocols they defined; they mostly didn't use init or static requirements, and when they did, it's mostly in protocols that also use Self or associatedtype. It would be a shame to make a language feature more obscure for the sake of an uncommon use case.

---

_[View the full topic](https://forums.swift.org/t/introduce-any-p-as-a-better-way-of-writing-existentials/39823)._
