我不熟悉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))
)