> On Dec 30, 2015, at 4:50 PM, Kevin Ballard via swift-dev > <swift-dev@swift.org> wrote: > > FWIW, once we have conditional protocol conformance (`extension ... : Proto > where ...`), and if we get rid of the circular protocol inheritance > limitation (two protocols that inherit from each other, which should in > theory be fine), then we can say something like > > protocol EquatableSequenceType : SequenceType { > func contains(element: Self.Generator.Element) -> Bool > } > > extension SequenceType : EquatableSequenceType where Self.Generator.Element : > Equatable { > func contains(element: Self.Generator.Element) -> Bool { > // ... > } > } > > This way the method can actually be overridden directly without requiring any > hacks like _customContainsEquatableElement. > > We could work around the circular protocol inheritance thing by declaring a > `typealias _Element : Equatable` in EquatableSequenceType instead of having > the inheritance, and then just set `typealias _Element = > Self.Generator.Element` in the protocol extension on SequenceType, but that > does in theory let implementing types actually change the type of the > contains() method parameter by overriding the typealias, which is a bit weird.
Tricks like this also usually break generic code because it can no longer count on the usual relationships between types. > Alternatively, we could work around it by allowing you to say `extension Any > : EquatableSequenceType where Self : SequenceType { ... }` and having that > essentially extend every concrete type that conforms to SequenceType, which > means SequenceType itself doesn't conform to EquatableSequenceType and > therefore there's no circular protocol inheritance, but I'm not sure if this > is actually an approach we want to take (although this is precisely what Rust > does and it works for them). I don’t want to create stdlib churn working around the lack of generics features that we expect to have for the next release. We should just wait for the generics system to be ready. -Dave _______________________________________________ swift-dev mailing list swift-dev@swift.org https://lists.swift.org/mailman/listinfo/swift-dev