In addition to the conciseness, I think one advantage of operators over (non-operator) functions is that they flatten out long expressions to make them easier to read.
For example, calculating the area of a triangle using Heron's formula:
func area(a: Double, b: Double, c: Double) -> Double {
((a + b - c) * (b + c - a) * (c + a - b) * (a + b + c)).squareRoot() / 4
}
is long but readable. However, if each operator is used like a function, it becomes much less readable with many layers of parentheses:
func area(a: Double, b: Double, c: Double) -> Double {
/(*(*(-(+(a, b), c),-(+(b, c), a)),*(-(+(c, a), b),+(+(a, b), c))).squareRoot(), 4)
}
If the functions are spelled out and placed in an enum, then you're more or less forced to write a biig pyramid:
func area(a: Double, b: Double, c: Double) -> Double {
Relaxed.multiply(
Relaxed.multiply(
Relaxed.multiply(
Relaxed.subtract(c, from: Relaxed.add(a, b)),
Relaxed.subtract(a, from: Relaxed.add(b, c))
),
Relaxed.multiply(
Relaxed.subtract(b, from: Relaxed.add(c, a)),
Relaxed.add(Relaxed.add(a, b), c)
)
).squareRoot(),
0.25
)
}
Would ~+ and ~* (also ~- and ~/ if relaxed subtraction and division are added too) work? I feel "~" conveys the sense of "not strict, relaxed".