Is "Protocol Inheritance" the same thing as "Protocols conforming to Protocols"

The answer is no. Protocols cannot conform to protocols.

It may be easier to understand if existential protocol types were spelled differently from concrete types. In the last code snippet, when you write Set<Category> you are using Category as the existential type containing all the concrete types conforming to the Category protocol. Set<Element>, however, requires its Element parameter type to conform to Hashable. Since existential protocol types cannot conform to protocols, you cannot use them.

The solution is to make Category a concrete type instead of a protocol.

If there was an explicit way to refer to existential protocol types, e.g. using any Category, you would be able to explicitly add conformances. It's a design already discussed. For more info check the section Clarifying existential types in Improving the UI of generics.

2 Likes