[swift-evolution] [proposal] default func ==(_:_:)

Haravikk e-mail at haravikk.me
Wed Jan 27 04:08:25 CST 2016

I like this idea.

Just a few thoughts:

Will we need some mechanism to mark properties that shouldn’t be compared?
What about computed properties, could we mark these such that they will be compared as well if relevant?
Could I still use this even if some of my properties aren’t equatable? e.g- if nine of ten properties are equatable, could I use this protocol to generate default behaviour for the nine equatable properties, then just add support for the non-equatable one?

If it will require compiler magic anyway (since we currently have no reflection API I assume it will, unless I’ve missed one), then adding support for some or all of these could make this the standard method of implementing equatable for the vast majority of classes.

> On 27 Jan 2016, at 09:14, Dave via swift-evolution <swift-evolution at swift.org> wrote:
> I’d expand that to allow any protocol to be annotated “@memberwise” or something, if their requirements can be satisfied in that manner.
> Have we already talked about this? I can’t remember.
> - Dave Sweeris
>> On Jan 27, 2016, at 00:40, Jan E. Schotsman via swift-evolution <swift-evolution at swift.org> wrote:
>> Feature name - provide default func ==(_:_:) for types declared Equatable
>> Author: Jan E.Schotsman
>> Introduction:
>> If all of a type's stored properties are Equatable it makes sense for Swift to provide a default equality implementation.
>> Motivation:
>> In a project where many large types are defined that need to be Equatable it gets cumbersome to write explicit equality functions for all types.
>> Proposed solution
>> If a type is declared Equatable, all its stored properties are Equatable and no func ==(_:_:) is defined by the developer the compiler will synthetisize a memberwise equality function.
>> (Recursiveness of this procedure is almost automatic)
>> Impact on existing code
>> There is no impact on existing code. Equality functions equal to the default implementation can simply be removed.
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> swift-evolution mailing list
> 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/20160127/3b02be27/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2475 bytes
Desc: not available
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160127/3b02be27/attachment.p7s>

More information about the swift-evolution mailing list