Where can I find a list of the infix Haskell operators in Prelude and base package in general, along with their precedence level, and whether they're right or left associative? I know this information is available in the documentation, but it's all spread out and mixed with descriptions and examples. I just want the list of these operators, without any descriptions, sorted by their precedence level and associativity. That is it.
CodePudding user response:
I found a way to generate this list automatically. First, write the operators to a file. Call it ops
:
import Data.Function
import Data.Functor
import Control.Monad
import Data.Bits
:info $ $! . & : !! <$ <$> $> >>= >> >=> <* <*> *> == /= < > <= >= && || - * / `div` `mod` `divMod` `seq` ** ^ ^^ `elem` `notElem` .&. .|.
Then run the following:
> cat ops | ghci | grep infix | LC_ALL=C sort -s -k 2,2 -k 1,1
infixr 0 $
infixr 0 $!
infixr 0 `seq`
infixl 1 &
infixl 1 >>=
infixl 1 >>
infixr 1 >=>
infixr 2 ||
infixr 3 &&
infix 4 ==
infix 4 /=
infix 4 <
infix 4 >
infix 4 <=
infix 4 >=
infix 4 `elem`
infix 4 `notElem`
infixl 4 <$
infixl 4 <$>
infixl 4 $>
infixl 4 <*
infixl 4 <*>
infixl 4 *>
infixl 5 .|.
infixr 5 :
infixr 5
infixl 6
infixl 6 -
infixl 7 *
infixl 7 /
infixl 7 `div`
infixl 7 `mod`
infixl 7 .&.
infixr 8 **
infixr 8 ^
infixr 8 ^^
infixr 9 .
>
Some operators won't appear in the output, because their fixity was unspecified. They have fixity infixl 9
, which is the default. Notably, this includes !!
.
CodePudding user response:
Page 51 of the Haskell Report has a table summarising the fixity of all Prelude operators.