[swift-evolution] [Discussion] Generic protocols

David Sweeris davesweeris at mac.com
Sat Dec 10 00:24:22 CST 2016

> On Dec 9, 2016, at 9:21 PM, Alexis via swift-evolution <swift-evolution at swift.org> wrote:
> I’m also pretty confident that allowing protocols to be multi-conformed without requiring some specific annotation on them is totally busted. The fact that you can uniquely determine the associated type of a conformance from the type of Self is an important property of the type system.
> That is, 
> func foo<S: Sequence>(seq: S) -> S.Item? { … }
> let x: [Int] = …
> let y = foo(x)
> Only works because ([Int] as Sequence).Item can be uniquely determined. Otherwise you would require an annotation at the call site to “pick” the conformance (in this case y: Int would probably be sufficient, but you can easily imagine more complex cases).

Why not just say that associated types can’t depend on generic types? Likewise, if you conform to the same generic protocol multiple times with different generic parameters, only functions which contain the generic parameter(s) in their signature would need to be reimplemented, otherwise it’s an invalid redeclaration.

- Dave Sweeris

More information about the swift-evolution mailing list