[swift-evolution] [Re-Review] SE-0104: Protocol-oriented integers

Brent Royal-Gordon brent at architechies.com
Wed Feb 22 22:13:35 CST 2017


> On Feb 22, 2017, at 10:55 AM, Max Moiseev via swift-evolution <swift-evolution at swift.org> wrote:
> 
>>     default func multiplied(by other: Self) -> Self // `default` means try resolving ambiguities with this version first. The overloaded versions are only considered if the type-checker can’t make this version work.
> 
> This feature is not strictly required in this case, as we moved away from using `multiplied` of type (Self, Self) -> Self to using proper `static func +`. So the ambiguity will *not* happen in the most common case when you want to multiply two numbers of some type and get the result of the same type. Ambiguity will only become a problem in what I believe to be a very less frequent case, when you want to do something very special, like, catch the overflow explicitly or get the full result in a form of DoubleWidth<T>.

True, but I think the only reason we're not using operators for the other `multiplied` variants is that they need the third parameter. So we could instead specify:

	default static func * (lhs: Self, rhs: Self) -> Self
	static func * (lhs: Self, rhs: Self) -> (partialValue: Self, overflow: ArithmeticOverflow)
	static func * (lhs: Self, rhs: Self) -> DoubleWidth<Self>

And not have to worry about these names at all.

(On the other hand, the reversed DoubleWidth division would still be a problem. But isn't there a proposal in the works to add `\` to the operator characters?)

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list