An operator is a function that can be applied in a infix position. So $
is a function.
In Haskell, you can define your own functions that can be used in infix position - between the arguments. Then you can also define function application precedence and associativity using infix
, infixr
, infixl
- that is, the clues telling the compiler whether to treat a $ b $ c
as (a $ b) $ c
, or a $ (b $ c)
.
The precedence of $
is such that your first expression is interpreted like (map head xs : abc) $ ...
For example, to declare $
as infix, place its name in ()
:
($) :: (a->b) -> a -> b
f $ x = f x
or composition:
(.) :: (b->c)->(a->b)->a->c
(f . g) x = f $ g x
Arithemtic "operators" are also defined as infix functions in class Num.
Additionally, you can use other functions as infix, by quoting them in backticks `` at the application site. Sometimes it makes the expression look prettier:
f `map` xs == map f xs
(not that in this particular case it makes it look pretty, just to show a simple example)