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 application op x y
, one can write the infix application x `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 to x + y
, and foldr (⋆) 1 xs
is equivalent to foldr (\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.
123 'func' 456
variant. But this is infix form only (in my opinion). This case thefunc
is not opereator. - Andrey Bushman((+) `foldr` 0) [1..10]
which usesfoldr
as an operator. - kosmikus