<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div><blockquote type="cite"><div class=""><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">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 </span></font></div></blockquote></div><div><br></div><div>That is exactly what I argue should be avoided. When you see `+` you don’t expect it to throw. What’s more they don’t carry “math” semantics at all because for example</div><div><br></div><div>Func * (Double, Measurement) -> Measurement is not even associative.</div><div>I agree that operators for this kind of functions should exist and are the right syntactic tool. But I disagree with the current implementation. My proposition for the example of `*` is as follow:</div><div><br></div><div>This signature happens quite often `(Number, T) -> T`. It would seem quite intuitive to have a dedicated operator for all “Scalar multiplication” which would be visually distinct from `*` (for example **, or Unicode <span style="background-color: rgba(255, 255, 255, 0);">⊗</span>) and consistent across codebases. </div><div><br></div><div>For a + operator that throws, I would imagine a “TryAddable” protocol with a `+!` operator which can throw. I agree that it is visual noise, but I argue that it has tremendous value: consistant operator semantics.</div><div><br></div><div><blockquote type="cite"><div class=""><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">(Also, I really doubt changing concatenation to `++` is going to fly. Swift is not Haskell.)</span></font></div></blockquote>I doubt those remarks are very constructive. The point still stands: I find value in having different operators for different semantics.</div><div><br>On 1 Sep 2017, at 01:54, Brent Royal-Gordon <<a href="mailto:brent@architechies.com">brent@architechies.com</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div><blockquote type="cite" class=""><div class="">On Aug 31, 2017, at 3:40 PM, André Videla via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">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.</span></div></blockquote></div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">(Also, I really doubt changing concatenation to `++` is going to fly. Swift is not Haskell.)</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px;"><div class=""><div style="font-size: 12px; " class="">-- </div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>
</div>
<br class=""></div></blockquote></body></html>