为什么需要括号来打印 . 的类型信息?

Why are brackets required to print type information of .?

要打印 . 的类型信息,我使用:

λ> :type (.)
(.) :: (b -> c) -> (a -> b) -> a -> c

如果我省略括号,会导致错误:

λ> :type .
<interactive>:1:1: parse error on input ‘.’

其他类型则不然:

λ> :type 1
1 :: Num a => a
λ> :type (1)
(1) :: Num a => a
λ> :type True 
True :: Bool
λ> :type (True)
(True) :: Bool

为什么 . 的特殊行为?

不带括号的

. 仅适用于中缀位置。 :t 但是需要一个表达式,例如一个函数,并且要将中缀运算符符号转换为表达式,您需要用括号将其括起来。

考虑:

3 + 4 = (+) 3 4  -- pseudocode

myPlus = (+)

相同
myPlus a b = a + b
myPlus a b = (+) a b

它同样适用于所有其他中缀运算符,例如 *>>=&&&