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?
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.
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.
:i
(:info
).
[Prelude]
> :i (+)
class Num a where
(+) :: a -> a -> a
...
-- Defined in `GHC.Num'
infixl 6 +
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