[swift-users] Overload by return type optionality?

Hooman Mehr hooman at mac.com
Thu Oct 13 19:37:44 CDT 2016


> On Oct 13, 2016, at 3:31 PM, Rick Mann via swift-users <swift-users at swift.org> wrote:
> 
> Would it make sense to be able to specify priority for a set of overloaded methods to help resolve ambiguity?

This might be pretty useful in some situations, but I am not sure if the semantic complexity that it introduces is worth it.

Another example of how this could be useful: 

I made a bare-bones rational number type <https://gist.github.com/hooman/6e08c48e1e06ee19e06e5b09f664f9be> for Swift a while ago. I would love to be able to overload “/“ operator to create fractions (rational numbers) instead of dividing two integers. 

If I overloaded “/“ to return rational (Int / Int -> Rational), the result type of the operator would become ambiguous for every use of it with integer operands. It would be nice if I could prioritize my overload of “/“ over stdlib definition to resolve the ambiguity. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161013/802c558b/attachment.html>


More information about the swift-users mailing list