我不熟悉OCaml,但已參與分析一些OCaml代碼。 這段代碼令我困惑。基於運算符優先級,正確的分組是什麼?OCaml優先
let new_fmt() =
let b = new_buf() in
let fmt = Format.formatter_of_buffer b in
(fmt,
fun() ->
Format.pp_print_flush fmt();
let s = Buffer.contents b in
Buffer.reset b;
s
)
這裏有三個操作符:「;」,「,」和「fun」。根據參考手冊,優先級爲 的順序是逗號>分號>有趣,我相信會導致下面的分組。 哪一個是OCaml編譯器挑選的?或者是否有另一個正確的分組?
分組1:
let new_fmt() =
let b = new_buf() in
let fmt = Format.formatter_of_buffer b in
((fmt,
fun() ->
Format.pp_print_flush fmt());
(let s = Buffer.contents b in
Buffer.reset b;
s)
)
分組2:
let new_fmt() =
let b = new_buf() in
let fmt = Format.formatter_of_buffer b in
(fmt,
(fun() ->
Format.pp_print_flush fmt();
let s = Buffer.contents b in
(Buffer.reset b;
s))
)