3 ms·
> Can you write an Either<> or a Parser<> (2- and 1-case enums respectively) which is driven by the known-and-loved ?, !, and ?? - or did the language designers
by Someone 2y ago
> Can you write an Either<> or a Parser<> (2- and 1-case enums respectively) which is driven by the known-and-loved ?, !, and ?? - or did the language designers keep that for themselves?
https://docs.swift.org/swift-book/documentation/the-swift-programming-language/lexicalstructure#Operators https://docs.swift.org/swift-book/documentation/the-swift-pr...:
“Although you can define custom operators that contain a question mark (?), they can’t consist of a single question mark character only. Additionally, although operators can contain an exclamation point (!), postfix operators can’t begin with either a question mark or an exclamation point.
Note
The tokens =, ->, //, /, /, ., the prefix operators <, &, and ?, the infix operator ?, and the postfix operators >, !, and ? are reserved. These tokens can’t be overloaded, nor can they be used as custom operators.”
So, you can’t use the same operator names. I would think you can implement them using different names, though.