Parsing Ocaml语法错误:为什么必须在函数应用程序中使用括号(if…)?

Parsing Ocaml语法错误:为什么必须在函数应用程序中使用括号(if…)?,parsing,ocaml,Parsing,Ocaml,将此代码输入到ocaml顶级将导致语法错误 (fun n -> n + 1) if true then 1 else 2 但是这个代码是可以的 (fun n -> n + 1) (if true then 1 else 2) 为什么需要括号?因为 f if a then b else x y 将是不明确的(除了难以阅读)。这是优先级表的结果。函数具有左关联性,而if没有关联性

将此代码输入到ocaml顶级将导致语法错误

(fun n -> n + 1) if true then 1 else 2
但是这个代码是可以的

(fun n -> n + 1) (if true then 1 else 2)

为什么需要括号?

因为

f if a then b else x y

将是不明确的(除了难以阅读)。

这是优先级表的结果。函数具有左关联性,而if没有关联性