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

Mike Kluev mike.kluev at gmail.com
Fri Sep 1 05:03:48 CDT 2017

on Fri, 1 Sep 2017 00:40:25 +0200 André Videla <andre.videla at gmail.com>

> Furthermore, I would argue that using `+` for matrices is more consistent
than the current definition of `+`.
> Indeed, the operator `+` is both used for combining numbers and combining
> The inconsistency comes from the fact that it is expected that `+` is a
commutative operator,
> but concatenation is not a commutative operation. Therefore the semantics
of `+` varies
> depending on the types that it’s used on. And, in my opinion, this
inconsistency is to be
> avoided when dealing with operators. Not to mention that nothing prevent
a library to override
> `+` with any nonsensical behaviour.

how would you multiply matrices, or multiply matrix by a number? let's say
you will use * for that. but matrix x matrix multiplication is not
commutative (while matrix x number is). would you propose to use ** instead?

if i have:

func * (m: Matrix, n: Double) -> Matrix

with * somehow marked "commutative", shall i be able using it as n*M
straight away without having explicit:

func * (n: Double, m: Matrix) -> Matrix

while using + for string concatenation is a long standing tradition it
is indeed a bit awkward (as awkward as 1 + 2 = 12 would be)

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

More information about the swift-evolution mailing list