To print the type information of .
I use :
λ> :type (.)
(.) :: (b -> c) -> (a -> b) -> a -> c
If I omit the brackets , causes an error :
λ> :type .
<interactive>:1:1: parse error on input ‘.’
The same is not true for other types :
λ> :type 1
1 :: Num a => a
λ> :type (1)
(1) :: Num a => a
λ> :type True
True :: Bool
λ> :type (True)
(True) :: Bool
Why the special behavior for .
?
.
without the parentheses only works in infix position. :t
however takes an expression, e.g. a function, and to turn an infix operator symbol into an expression, you need to surround it with parens.
Consider:
3 + 4 = (+) 3 4 -- pseudocode
and
myPlus = (+)
which is the same as
myPlus a b = a + b
myPlus a b = (+) a b
And it applies equally to all other infix operators such as *
or >>=
or &&&
etc.