为什么用这个表达式中的圆括号代替美元符号($)会导致错误? [英] Why does replacing the dollar sign ($) with parentheses in this expression leads to an error?
本文介绍了为什么用这个表达式中的圆括号代替美元符号($)会导致错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这两个表达式:
I have these two expressions:
-
foldr( - )0。 map(uncurry(*))$ coords 5 7
foldr( - )0。地图(uncurry(*))(coords 5 7)
工作打印结果,但(2)有错误说:
The (1) works print out the result, but (2) have error says:
<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)
有没有人能告诉我这两个?感谢。
Can any one tell me what's the difference between these two? Thanks.
推荐答案
有一个更简单的例子:
There's an easier example:
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")
问题是函数应用程序绑定比 (。)
。 ($)
的固定级别解决了这个问题:
The problem is that function application binds stronger than (.)
. The fixity level of ($)
fixes this:
id . id $ "Example" = (id . id) $ "Example"
= (id . id) "Example"
例子=(id。id)$例子
=(id。id)
但是,使用(...)
时,函数应用程序会赢,最终使用(。)
作为第二个参数:
However, with (...)
, the function application wins and you end up using (.)
with a non-function as second argument:
id . id ("Example") = id . id "Example"
= id . (id "Example") -- apply id
= id . ("Example")
= type error, since "Example" isn't a function
这篇关于为什么用这个表达式中的圆括号代替美元符号($)会导致错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文