[swift-evolution] Beyond Typewriter-Styled Code in Swift, Adoption of Symbols

Brent Royal-Gordon brent at architechies.com
Thu Aug 31 18:54:15 CDT 2017


> On Aug 31, 2017, at 3:40 PM, André Videla via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Something I could imagine is deprecate operator overloading and constrain them to a single Type. For example, the operator `+` could be constrained to the protocol `Addable` and has the signature `infix func + (Self, Self) -> Self` and is commutative. Similarly, we could have a protocol `Concatenable` which has its own operator (e.g.: ++ ) and is not commutative.


These are basically "bag of syntax protocols" which aren't really usable generically, so we don't want this design. And if you tied this to the numeric protocols, then you couldn't use `+` for things that are numeric-ish but don't quite fit the protocols. For instance, I have a library that adds `+` and `*` operators to `Foundation.Measurement`; these versions of the math operators don't quite work the same way as the standard ones (e.g. `+` can throw), but they still carry math semantics and so `+` is the right operator for them. If `+` was exclusively tied to a particular protocol with a particular signature, I wouldn't be able to do that.

(Also, I really doubt changing concatenation to `++` is going to fly. Swift is not Haskell.)

-- 
Brent Royal-Gordon
Architechies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170831/c403e444/attachment.html>


More information about the swift-evolution mailing list