Haskell operator vs function precedence

Firstly, application (whitespace) is the highest precedence “operator”.

Secondly, in Haskell, there’s really no distinction between operators and functions, other than that operators are infix by default, while functions aren’t. You can convert functions to infix with backticks

2 `f` x

and convert operators to prefix with parens:

(+) 2 3

So, your question is a bit confused.

Now, specific functions and operators will have declared precedence, which you can find in GHCi with “:info”:

Prelude> :info ($)
($) :: (a -> b) -> a -> b   -- Defined in GHC.Base

infixr 0 $

Prelude> :info (+)

class (Eq a, Show a) => Num a where
  (+) :: a -> a -> a

infixl 6 +

Showing both precedence and associativity.

Leave a Comment