[swift-evolution] [swift-evolution-announce] [Review] SE-0067: Enhanced Floating Point Protocols

Chris Lattner clattner at apple.com
Wed Apr 27 14:58:52 CDT 2016


> On Apr 27, 2016, at 10:54 AM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
> on Tue Apr 26 2016, Chris Lattner <swift-evolution at swift.org> wrote:
> 
>> On Apr 26, 2016, at 7:34 PM, Tony Allevato via swift-evolution <swift-evolution at swift.org> wrote:
>>> Would something like this be possible? Imagine protocols defined like this:
>>> 
>>>  public protocol Equatable {
>>>      static func == (lhs: Self, rhs: Self) -> Self
>>>  }
>> 
>> The problem is that every type that conforms to Equatable has to
>> provide an overload of == in order to conform.  This is exactly what
>> having named methods as requirements solves.
> 
> Note that Tony is proposing to make the requirement static.  Whether
> it's actually called “==” or isEqual is almost immaterial, because the
> fact that it is static makes it less likely that anyone will try to call
> it directly.  
> 
> However, if we allowed static operators to be defined, and called using
> the syntax “T.==(x,y)”, as Tony has suggested, IMO it would further
> discourage direct use, and it would avoid growing the number of
> truly distinct spellings for the same operation.

Ah, that is clever!

-Chris


More information about the swift-evolution mailing list