> On 22 Feb 2017, at 13:19, Derrick Ho <[email protected]> wrote:
>
> I've read the pitch, but it isn't clear what the ask is or what benefit it
> would give.
The purpose of the feature is to enable selection of identically named methods
with similar signatures. This came up in the protocol-oriented integers debate
on the ability to have arithmetic methods with and without overflow. Like so:
protocol IntegerArithmetic {
func adding(_ other:Self) -> Self
func adding(_ other:Self, reportingOverflow) -> (Self, Bool)
}
var a = 2, b = 3
let resultWithoutOverflow = a.adding(b)
let resultWithOverflow = a.adding(b, reportingOverflow)
Here we have two different methods, one reporting overflow and one without,
using the label to enable selection, rather than having to have an
addingWithOverflow() method or similar.
Currently the alternative is to do something like:
enum ReportingOverflow { case .reportingOverflow }
protocol IntegerArithmetic {
func adding(_ other:Self) -> Self
func adding(_ other:Self, _) -> (Self, Bool)
}
var a = 2, b = 3
let resultWithoutOverflow = a.adding(b)
let resultWithOverflow = a.adding(b, .reportingOverflow)
Basically the ability to use the label for method selection is an alternative
to either defining an enum as above, or having to use a different method name._______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution