Symbol is considered to be an identifier, not an operator
The characters allowed in a custom operator is listed in The Swift Programming Language, and € is not one of these. (You could also find corresponding Lexer code).
The main difference between the two currency symbols is that £ (and also ¢ and ¥) are in the Latin-1 supplement block (U+0080 – U+00FF), while € is in the Currency Symbols block (U+20A0 – U+20CF), and for some reason the Swift language considers these as identifier-like instead of operator-like.
The first character of an operator must be one of these:
.
/=-+!*%<>&|^~?
- Latin-1 supplement:
¡¢£¤¥¦§©«¬®°±¶»¿×÷
- General Punctuation:
‖‗†‡•‣․‥…‧‰‱′″‴‵‶‷‸‹›※‼‽‾⁁⁂⁃⁄⁅⁆⁇⁈⁉⁊⁋⁌⁍⁎⁏⁐⁑⁒⁓⁕⁖⁗⁘⁙⁚⁛⁜⁝⁞
- Arrows (U+2190 – U+21FF): Whole block
- Mathematical operators (U+2200 – U+22FF): Whole block
- Miscellaneous Technical (U+2300 – U+23FF): Whole block
- Box Drawing (U+2500 – U+257F): Whole block
- Block Elements (U+2580 – U+259F): Whole block
- Geometric Shapes (U+25A0 – U+25FF): Whole block
- Miscellaneous Symbols (U+2600 – U+26FF): Whole block
- Dingbats (U+2700 – U+27BF): All except the circled numbers ❶–❿,➀–➉,➊–➓
- Miscellaneous Math Symbols-A (U+27C0 – U+27EF): Whole block
- Supplemental Arrows-A (U+27F0 – U+27FF): Whole block
- Braille Patterns (U+2800 – U+28FF): Whole block
- Supplemental Arrows-B (U+2900 – U+297F): Whole block
- Miscellaneous Math Symbols-B (U+2980 – U+29FF): Whole block
- Supplemental Math Operators (U+2A00 – U+2AFF): Whole block
- Miscellaneous Symbols and Arrows (U+2B00 – U+2BFF): Whole block
- Supplemental Punctuation (U+2E00 – U+2E7F): Whole block
- CJK Symbols and Punctuation:
、。〃〈〉《》「」『』【】〒〓〔〕〖〗〘〙〚〛〜〝〞〟〠〡〢〣〤〥〦〧〨〩〪〭〮〯〫〬〰
The rest of the operator can also be one of these characters:
- Combining Diacritical Marks (U+0300 – U+036F): Whole block
- Combining Diacritical Marks Supplemental (U+1DC0 – U+1DFF): Whole block
- Combining Diacritical Marks for Symbols (U+20D0 – U+20FF): Whole block
- Variation Selectors (U+FE00 – U+FE0F): Whole block
- Combining Half Marks (U+FE20 – U+FE2F): Whole block
- Variation Selectors Supplement (U+E0100 – U+E01FF): Whole block
A
.
can appear at the rest of an operator only if the first character is a.
.
What is the `Operator` word definition?
Ok, because there's so much confusion, I've decided to give yet another answer.
Here's the quote from the Haskell 2010 report:
Haskell provides special syntax to support infix notation. An operator is a function that can be applied using infix syntax (Section 3.4), or partially applied using a section (Section 3.5).
An operator is either an operator symbol, such as
+
or$$
, or is an ordinary identifier enclosed in grave accents (backquotes), such as`op`
. For example, instead of writing the prefix applicationop x y
, one can write the infix applicationx `op` y
. If no fixity declaration is given for`op`
then it defaults to highest precedence and left associativity (see Section 4.4.2).Dually, an operator symbol can be converted to an ordinary identifier by enclosing it in parentheses. For example,
(+) x y
is equivalent tox + y
, andfoldr (⋆) 1 xs
is equivalent tofoldr (\x y -> x⋆y) 1 xs
.
So this defines two notions, an "operator symbol" and an "operator". An "operator symbol" is any symbolic identifier. An "operator" is any function that can be applied using infix syntax.
So now let's look at your examples, one by one:
First example
(!#$%&*+./<=>?@\^|-~:) :: Int -> Int -> Int
a !#$%&*+./<=>?@\^|-~: b = a * b
The identifier !#$%&*+./<=>?@\^|-~:
is an operator symbol. If used in infix
position, such as on the left hand side of this definition, it's used as an
operator.
You give two examples of its use:
λ: 10 !#$%&*+./<=>?@\^|-~: 20
200
λ: (!#$%&*+./<=>?@\^|-~:) 40 20
800
In the first, we use it as an operator. In the second, we don't.
Second example
(!#$%&*+./<=>?@\^|-~:) :: Int -> Int
(!#$%&*+./<=>?@\^|-~:) a = a * a
It's the same name, so it's still an operator symbol. The definition uses the
parenthesized form, so it's not used as an operator here.
Neither in your examples:
λ: (!#$%&*+./<=>?@\^|-~:) 3 5 6
14
λ: (3 !#$%&*+./<=>?@\^|-~: 5) 6
14
Both use prefix syntax. It's syntactically possible to use this as an operator, but it'll necessarily yield a type error.
Third exampe
(!#$%&*+./<=>?@\^|-~:) :: Int -> Int -> Int -> Int
(!#$%&*+./<=>?@\^|-~:) a b c = a + b + c
Again, it's the same name, so it's still an operator symbol. It's not used as an operator in the definition, because it is prefix.
Your use cases also use prefix syntax:
λ: (!#$%&*+./<=>?@\^|-~:) 3 5 6
14
λ: (3 !#$%&*+./<=>?@\^|-~: 5) 6
14
But this one can easily be used in infix position, i.e., as an operator:
λ: (3 !#$%&*+./<=>?@\^|-~: 5) 6
14
Yet another example
Consider the following definition:
($$$) :: a -> a
($$$) x = x
Here, $$$
is also an operator symbol. The definition does not use it as an operator, but in prefix notation. However, it also can be used in infix position, e.g. in
λ: negate $$$ 3
-3
Concluding remark
Informally, people will probably talk about functions and operators in non-consistent ways in Haskell because there's really little difference. All are just functions. Being able to use things in infix notation is just syntactic sugar. So the important thing for programming in Haskell is to know the syntactic rules, such as that you can enclose identifiers in backquotes or surround symbols with parentheses. It's less important to know the exact definition of "operator". That's just a name.
Do identifier rules apply for operator overloading function?
From §3.1
A name is a use of an identifier (2.11), operator-function-id (13.5), literal-operator-id (13.5.8), conversion-function-
id (12.3.2), or template-id (14.2) that denotes an entity or label (6.6.4, 6.1).
So, as you can see, there are rules for the identifiers (which are the variable/function names). But there are some exceptions, and operator overloading (operator-function-id) is one of them, which means different rules apply to them.
From §13.5:
operator-function-id: operator operator
operator: one of
new delete new[] delete[]
+ - * / % ˆ & | ~
! = < > += -= *= /= %=
ˆ= &= |= << >> >>= <<= == !=
<= >= && || ++ -- , ->* ->
( ) [ ]
So, operator+
is allowed, operator-
also, basically operator
+ any of the operators listed above
.
Is ??? a valid symbol or operator in scala
Yes, this is a valid identifier.
Since Scala 2.10, there is a ???
method in Predef which simply throws a NotImplementedError
.
def ??? : Nothing = throw new NotImplementedError
This is intended to be used for quickly sketching the skeleton of some code, leaving the implementations of methods for later, for example:
class Foo[A](a: A) {
def flatMap[B](f: A => Foo[B]): Foo[B] = ???
}
Because it has a type of Nothing
(which is a subtype of every other type), it will type-check in place of any value, allowing you to compile the incomplete code without errors. It's often seen in exercises, where the solution needs to be written in place of ???
.
Is this - an old operator or a typo/error?
It looks like a problem in the transcription process. There is a similar problem in DR 42, where the greater than sign is doubled: http://www.open-std.org/jtc1/sc22/wg14/docs/rr/dr_042.html
Related Topics
Swiftui: Using View Modifiers Between Different iOS Versions Without #Available
Swift - Segue from Button Inside a Cell
Get Color of Point in a Skscene Swift
Accurately Get a Color from Pixel on Screen and Convert Its Color Space
How to Animate Changes to an @Observedobject
Problems Accessing Calendar Using Ekeventstore on Osx Sierra with Swift 3
Different Colors for Bars in Barchart Depend on Value
App Crashes from IPA File But Runs Fine from Xcode
Using Xcode to Cross-Compile Swift to Linux
How to Test Asynchronous Methods Swift
How to Deal with Buffered Strings from C in Swift
Swift Probability of Random Number Being Selected