[swift-evolution] [Pitch] Make Optional, Array, and Dictionary conditionally Equatable

Douglas Gregor dgregor at apple.com
Wed Nov 22 12:28:56 CST 2017



Sent from my iPhone

> On Nov 22, 2017, at 10:12 AM, Dave DeLong <swift at davedelong.com> wrote:
> 
> 
> 
>> On Nov 21, 2017, at 11:51 PM, Douglas Gregor via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Hi all,
>> 
>> We’re having a bit of a debate over the question of whether SE-0143 “Conditional Conformances” actually proposes any standard library changes at all, or whether they should all be brought up separately. So, I’ll pitch the pieces that I’d love to put into 4.1 to see if they’re as obvious as I think they should be :)
>> 
>> Proposal: make Optional, Array, ArraySlice, ContiguousArray, and Dictionary conform to Equatable when their type parameters are Equatable (and Set always conform to Equatable). Specifically, add to the standard library:
>> 
>> 	extension Optional: Equatable where Wrapped: Equatable { /*== already exists */ }
>> 	extension Array: Equatable where Element: Equatable { /*== already exists */ }
>> 	extension ArraySlice: Equatable where Element: Equatable { /*== already exists */ }
>> 	extension ContiguousArray: Equatable where Element: Equatable { /*== already exists */ }
>> 	extension Dictionary: Equatable where Value: Equatable { /*== already exists */ }
>> 	extension Set: Equatable { /*== already exists */ }
>> 
>> Motivation: we need these for ==/!= to properly compose. It’s a highly-requested feature and an obvious “first use” of conditional conformances for the standard library that is unlikely to break any code.
>> 
>> Implementation: https://github.com/apple/swift/pull/13046
>> 
>> Thoughts?
> 
> The reason these are on concrete types and not, say, Collection is because we can’t conditionally conform protocols yet, right?

Right. SE-0143 has a discussion of this limitation. 

  - Doug

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


More information about the swift-evolution mailing list