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

Jan E. Schotsman jeschot at xs4all.nl
Sat Jan 30 03:41:27 CST 2016


I would like some more discussion of the proposal for a default  
memberwise equality function for compound types.

It was suggested that some stored properties might be excluded from  
the comparison for equality.
Also calculated properties might be included (presumably if at least  
two stored properties are excluded).
Wouldn’t this complicate things too much (requiring two keywords?)
If only 9 properties  out of 10 are equatable should equality be based  
on that? What about 5 in 10?

Generalisation of the mechanism (applying a protocol to aggregates of  
types satisfying the protocol) was suggested using a ‘memberwise’  
annotation of the protocol.
Even in case of simple protocols like Equatable, SignedIntegerType  
this requires a specific implementation.
In case of Equatable the memberwise comparison results must be  
“anded”, for SignedIntegerType  the IntMax initializer must be  
replaced by a tuple.
IMHO in case of custom protocols it is unlikely that the compiler can  
guess (or be instructed in a simple way to provide) the intended  
implementation.

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


More information about the swift-evolution mailing list