我从ocaml开始尝试:
float_of_int 8/2 ;;
我期望它返回4.0,因为8/2是4,但是我收到一条错误消息:
Error: This expression has type float but an expression was expected of type
int
我在这里想念什么?
您的表达式解析如下:
(float_of_int 8) / 2
因此,您要使用来将浮点数除以/
int。
函数应用程序(在OCaml中并排放置两个表达式表示)具有很高的优先级,高于所有二进制中缀运算符。因此,您需要使用括号。
如果您这样写,它将起作用:
float_of_int (8/2)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句