# A new way to allow text and unicode operators?

Two impossible features brought together as one possible one...

In the past, we have had many requests for text operators, that is something like:

a and b
x union y


These are not possible because of a technicality of how the compiler's parser works combined with swift's operator syntax (i.e. Is aandb a word itself or a and b without spaces?).

We have also had requests for unicode operators (which are possible... depending on the particular character). But any requests to use them in the standard library have failed due to the difficulty of typing unicode quickly. (There was also the issue of reading the code in editors that don't support unicode)

I was working on something to do with LaTeX, and it gave me an idea. LaTeX can print pretty much any math symbol, and you write the math symbol \symbolName (e.g. \pi).

What if we used a similar approach allowing any word surrounded in single quotes to be declared as an operator using the normal syntax:

infix operator myOp: precedence


In addition, we could associate one of these declarations with a unicode character that represents it. For example (strawman syntax):

infix operator union "\u{222A}": precedence


In use, the operator would still show as text:

let a = x union y


but fancy editors like Xcode would have the option to display the associated unicode character (likely with some visual effect to show it is different than a user typed character. i.e. similar to how color/image literals are handled). Rollover would show the underlying text to aid in learning.

let a = x ∪ y //rolling over shows 'union'


This would make Swift's unicode support much easier to actually use in practice (remembering a word to type is much easier than a number code). It is also backwards compatible with those using editors that only support ascii (they would just see x 'union' y). Graceful degradation...

In the future, single quoted words which haven't been defined as operators could potentially be similarly associated with a unicode display string, and used elsewhere.

let 'dogcow' = "Moof!"


Even if these types of declarations never get used in the standard library, it still makes it much easier for all of us to actually use unicode symbols when we want to...

I really want to use letters in Operator definition. It is a way for generic programming for an associativity and reading reasons. For example I want to define any comparable function witch works another way than Comparable or Equatable in the standard library.
The only way to do it now is making a method:

protocol TimeLineComparable {
associatedtype Difference
func compareWith(lhs: Self) -> Difference
}

struct TimeLineComparison<Timeline: TimeLineComparable> {
let lhs: Timeline
let rhs: Timeline
func compareOnEquailPosition() {
let result = lhs.compareWith(lhs: rhs)
let resulttwo = rhs.compareWith(lhs: lhs)
// result == resulttwo ???
}
}


Or making an abstract operator

infix operator ----

protocol TimeLineComparable {
associatedtype Difference
static func ---- (lhs: Self, rhs: Self) -> Difference
}


But I want do it more natural with an operator, which could suggest me what exactly he does:

infix operator --CompareTimeLines--
protocol TimeLineComparable {
associatedtype Difference
static func --CompareTimeLines-- (lhs: Self, rhs: Self) -> Difference
}

struct TimeLineComparison<Timeline: TimeLineComparable> {
let lhs: Timeline
let rhs: Timeline
func compareOnEquailPosition() {
let difference = lhs --CompareTimeLines-- rhs
// Now it’s obvious that the only ONE difference is
}
}