假设我想用Text.pack
撰写Text.strip
。
:t (.)
生成:(b -> c) -> (a -> b) -> a -> c
:t (Text.pack)
生成:String -> Text
:t (Text.strip)
生成:Text -> Text
用strip
代替(b -> c)
给出:
b = Text
c = Text
将pack
替换为(a -> b)
给出:
a = String
b = Text
让我们验证::t strip . pack
产生:
strip . pack :: String -> Text
strip.pack " example "
产地:
Couldn't match expected type ‘a -> Text’ with actual type ‘Text’
Relevant bindings include
it :: a -> Text (bound at <interactive>:31:1)
Possible cause: ‘pack’ is applied to too many arguments
In the second argument of ‘(.)’, namely ‘pack " example "’
In the expression: strip . pack " example "
(strip . pack) " example "
按预期工作....为什么?
答案 0 :(得分:11)
功能应用程序的优先级高于组合。
strip.pack " example "
相当于strip.(pack " example ")
。这是人们在编写完所有函数之前使用$
来“抑制”应用程序的一个原因:
strip . pack $ " example "
答案 1 :(得分:1)
函数应用程序的优先级高于函数组合运算符。