[swift-evolution] [Proposal] Conditional Conformance on Protocols/Generic Types

Dan Zimmerman daniel.zimmerman at me.com
Sat Jun 4 16:20:05 CDT 2016


Hey- 
Thanks for the quick response and for pointing me in the right direction!

Dan

> On Jun 4, 2016, at 4:18 PM, Austin Zheng <austinzheng at gmail.com> wrote:
> 
> Hello Dan,
> 
> You'll be pleased to learn that conforming generic types conditionally to protocols is on the roadmap (and is one of the highest priority items for the versions of Swift following 3.0): https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#conditional-conformances- <https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#conditional-conformances->
> 
> However, it's unlikely that protocols will gain conditional conformance: https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#conditional-conformances-via-protocol-extensions <https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#conditional-conformances-via-protocol-extensions>
> 
> That document originates from a mailing list post made some time ago, and is a decent overview as to what sorts of type system features the Swift core developers are interested in building.
> 
> Best,
> Austin
> 
>> On Jun 4, 2016, at 2:12 PM, Dan Zimmerman via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Hey,
>> 
>> I was interested in adopting the ability for a type that's generic in some sense (either via generics or via associated types, in the case of protocols) to conform to other protocols conditionally based on its type parameter/associated type. For example:
>> 
>> ```
>> extension CollectionType: Equatable where Generator.Element: Equatable {}
>> 
>> func ==<Collection: CollectionType where Collection.Generator.Element: Equatable>(left: Collection, right: Collection) -> Bool {
>>  return zip(left, right).reduce(true) { accumulator, tuple in accumulator && (tuple.0 == tuple.1) }
>> }
>> ```
>> 
>> If this has already been proposed and knocked out/accepted please direct me to the right place.
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160604/4d52d471/attachment.html>


More information about the swift-evolution mailing list