我有这两种表达方式:
foldr (-) 0 . map (uncurry (*)) $ coords 5 7
foldr (-) 0 . map (uncurry (*)) (coords 5 7)
(1) 工作打印出结果,但 (2) 有错误说:
<interactive>:50:15:
Couldn't match expected type ‘a -> t0 c’
with actual type ‘[Integer]’
Relevant bindings include
it :: a -> c (bound at <interactive>:50:1)
Possible cause: ‘map’ is applied to too many arguments
In the second argument of ‘(.)’, namely
‘map (uncurry (*)) (coords 5 7)’
In the expression: foldr (-) 0 . map (uncurry (*)) (coords 5 7)
谁能告诉我这两者有什么区别?谢谢。
有一个更简单的例子:
Prelude> id . id $ "Example"
"Example"
Prelude> id . id ("Example")
<interactive>:2:10:
Couldn't match expected type ‘a -> c’ with actual type ‘[Char]’
Relevant bindings include it :: a -> c (bound at <interactive>:2:1)
In the first argument of ‘id’, namely ‘("Example")’
In the second argument of ‘(.)’, namely ‘id ("Example")’
In the expression: id . id ("Example")
问题是函数应用程序的绑定比(.)
。固定水平为($)
解决这个问题:
id . id $ "Example" = (id . id) $ "Example"
= (id . id) "Example"
然而,随着(...)
,函数应用程序获胜,您最终使用(.)
以非函数作为第二个参数:
id . id ("Example") = id . id "Example"
= id . (id "Example") -- apply id
= id . ("Example")
= type error, since "Example" isn't a function
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)