6 haskell pointfree function-composition
作为Haskell的新手,我无法理解为什么表达式
head . words “one two three four”
抛出异常并且函数组合head . words
必须与$
运算符一起应用- 右侧的表达式不需要进一步评估,因为它只是一个单独的String
.编译它的另一种方法是放入head . words
括号但是(head . words) :: String -> String
具有相同的类型,head . words :: String -> String
为什么将它放在括号中使表达式编译?
Wil*_*ess 11
因为优先规则.应用程序具有最高优先级; $
- 最低.
head . words “one two three four”
被解析为head . (words “one two three four”)
即words
应用于字符串必须产生一个函数(如所要求的(.)
).但那不是那种类型words
:
Prelude> :t words
words :: String -> [String]
Run Code Online (Sandbox Code Playgroud)
head . words $ “one two three four”
另一方面,解析为(head . words) “one two three four”
和类型适合.
归档时间: |
|
查看次数: |
242 次 |
最近记录: |