Ocaml _int-3的float_是如何计算的?
我认为函数应用程序具有最高的优先级,因此Ocaml _int-3的float_是如何计算的?,ocaml,Ocaml,我认为函数应用程序具有最高的优先级,因此float\u of_int-3等于float\u of_int(-3)。为什么我需要显式地将括号放在那里以抑制错误?正是因为这个原因,函数应用程序的优先级高于中缀运算符,所以必须添加括号 换句话说,函数应用程序是贪婪的,它将使用所有项,直到它到达中缀运算符,例如 # float_of_int -3;; Error: This expression has type int -> float but an expression was
float\u of_int-3
等于float\u of_int(-3)
。为什么我需要显式地将括号放在那里以抑制错误?正是因为这个原因,函数应用程序的优先级高于中缀运算符,所以必须添加括号
换句话说,函数应用程序是贪婪的,它将使用所有项,直到它到达中缀运算符,例如
# float_of_int -3;;
Error: This expression has type int -> float
but an expression was expected of type int
被解析为(fxyz)+(gpqr)
你的例子也是如此
f x y z + g p q r
被解析为
float_of_int - 3
另一种选择是使用特殊的前缀运算符~-
,例如
(float_of_int) - (3)
比函数应用程序的绑定更紧密
float_of_int ~-1