Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check Haskell infix operator precedence

Tags:

I can see the type of an infix operator in GHCi with :t like so:

>:t (.)
(.) :: (b -> c) -> (a -> b) -> a -> c

How can i see the operator precedence in GHCi? is that possible?

Also, bonus question, is there a way to see the source of these prelude functions through ghci?

like image 998
Adam Gordon Bell Avatar asked Sep 02 '12 18:09

Adam Gordon Bell


People also ask

Does Haskell use infix notation?

Functions in Haskell default to prefix syntax, meaning that the function being applied is at the beginning of the expression rather than the middle. Operators are functions which can be used in infix style.

How do you define an infix function in Haskell?

There's no way to define a function with an alphanumeric name as infix. Haskell's syntax rules only allow for functions with symbolic names or function names surrounded with backticks to be used infix - there's no way to change that.


1 Answers

:i (:info).

[Prelude]
> :i (+)
class Num a where
  (+) :: a -> a -> a
  ...
        -- Defined in `GHC.Num'
infixl 6 +
like image 190
Cat Plus Plus Avatar answered Sep 28 '22 23:09

Cat Plus Plus