[swift-evolution] [Proposal] Instance Operators

Haravikk swift-evolution at haravikk.me
Fri Mar 4 16:49:36 CST 2016


Actually that’s what I was referring to; the difficulty is how to convert existing implementations of an equals operator into the new format, which means we’d probably have to just remove it from Equatable, require an equals() method then force developers to update their code.

i.e- if someone already has:

	func == (lhs:MyType, rhs:MyType) -> Bool { /* Do some stuff */ }

It’s not clear whether it would be safe just covert that into an equals() method, removing the lhs parameter and replacing it with references to self instead. It might just be one of those changes that has to break code, but will be better in the long-run.

> On 4 Mar 2016, at 21:53, davesweeris at mac.com wrote:
> 
> Why not do it the other way around, like this?
> func == <T: Equatable> (lhs: T, rhs: T) -> Bool {
> 	return T.equals(lhs, rhs)
> }
>> On Mar 4, 2016, at 3:40 PM, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> ...
>> This should be relatively simple to implement since in many ways we’re actually just getting rid of a feature, though of course the impact on code is more complex and probably not an easy one to convert automatically (as it would mean somehow pulling global == declarations into a local .equals() method and similar on affected types).
>> 
>> But I think in the long run it’s a cleaner system, and offers all the flexibility we need.
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution




More information about the swift-evolution mailing list