[swift-evolution] Optional comparison operators
jtbandes at gmail.com
Thu Jul 7 16:37:12 CDT 2016
These operators cause some potential for confusion:
public func <<T : Comparable>(lhs: T?, rhs: T?) -> Bool
public func ><T : Comparable>(lhs: T?, rhs: T?) -> Bool
public func <=<T : Comparable>(lhs: T?, rhs: T?) -> Bool
public func >=<T : Comparable>(lhs: T?, rhs: T?) -> Bool
1. The meaning of T? < T? is not immediately obvious (Why is nil < .some(x)
for any x? Personally, my intuition says that Optional should only provide
a partial order, with .none not being ordered w.r.t. .some(x).)
2. Even if the meaning is understood, it can be surprising when the (T?,
T?) -> Bool version is used instead of (T, T) -> Bool.
- Replies to https://twitter.com/jtbandes/status/646914031433871364
In the swift-dev thread from May, Chris said:
One of the ideas that Joe Pamer has been discussing is whether the implicit
>> promotion from T to T? should be disabled when in an operator context.
>> Doing so would fix problems like this, but making the code invalid.
A change like this would be source-breaking, so if the core team has
recommendations for how to handle these issues, now is probably the time to
get it done.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution