[swift-evolution] [Proposal] Instance Operators
Haravikk
swift-evolution at haravikk.me
Fri Mar 4 15:40:54 CST 2016
> On 4 Mar 2016, at 12:54, Andrew Bennett via swift-evolution <swift-evolution at swift.org> wrote:
>
> I'm +1 on Nicola's suggestions.
>
> Basically, remove operators from protocols, simplifying the language. This doesn't prevent operators from using protocols (through generics).
>
> Operators with protocols can still be defined as Nicola suggested, through a regular protocol method and a generic. Symmetrical operators can use a static method on the protocol if that's desirable. Swift has all the functionality for this already.
>
> It also doesn't have the downside of preventing operators from working on things like types, tuples, etc.
Having thought about it I think that this a good summary of my thoughts now too; by having protocols like Equatable specify method requirements instead of operators we can get the best of both worlds without having to introduce a new syntax for specifying operators as instance-specific constructs.
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.
More information about the swift-evolution
mailing list