When the language extension TypeOperators
is enabled, it's possible to define own type operators. Also, it's possible to set their relative precedence with infix*
. But what's the precedence of (->)
, for example?
> :i (->)
data (->) a b -- Defined in `GHC.Prim'
instance Monad ((->) r) -- Defined in `GHC.Base'
instance Functor ((->) r) -- Defined in `GHC.Base'
instance Applicative ((->) a) -- Defined in `Control.Applicative'
instance Arrow (->) -- Defined in `Control.Arrow'
instance Monoid b => Monoid (a -> b) -- Defined in `Data.Monoid'
instance ArrowLoop (->) -- Defined in `Control.Arrow'
instance ArrowChoice (->) -- Defined in `Control.Arrow'
instance ArrowApply (->) -- Defined in `Control.Arrow'
Here are the relevant bits of the GHC sources in compiler/basicTypes/BasicTypes.lhs
:
maxPrecedence, minPrecedence :: Int
maxPrecedence = 9
minPrecedence = 0
defaultFixity :: Fixity
defaultFixity = Fixity maxPrecedence InfixL
negateFixity, funTyFixity :: Fixity
-- Wired-in fixities
negateFixity = Fixity 6 InfixL -- Fixity of unary negate
funTyFixity = Fixity 0 InfixR -- Fixity of '->'
So the fixity of ->
is infixr 0
.
You can also infer this from an error message. Create the following Haskell source file:
{-# LANGUAGE TypeOperators #-}
data a // b
infixl 0 //
Then:
GHCi> :kind Int // Int -> Int
<interactive>:1:5:
Precedence parsing error
cannot mix ‘//’ [infixl 0] and ‘(->)’ [infixr 0] in the same infix expression
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With