【发布时间】:2020-08-04 19:30:00
【问题描述】:
我正在尝试了解 2 个 OCaml 运算符:@@ 和 |>
我知道x |> f 只是f(x),但它为什么存在呢?我不明白为什么。 @@ 也是如此,据我了解,这只是普通的功能应用程序
例如:
match get_ipv4_hlen_version buf |> version with
| 0x40 -> Ok buf
| n -> Error (Printf.sprintf "IPv4 presented with a packet that claims a different IP version: %x" n)
为什么不直接写get_ipv4_hlen_version version buf?
怎么样
let options_len = nearest_4 @@ Cstruct.len t.options
为什么不let options_len = nearest_4 Cstruct.len t.options
?
我想这与优先级有关,我记得一些来自 Haskell 的东西,但我不知道 Haskell,我只是在某处读过。
我如何知道事物的优先级?
如果需要更多上下文,这两个代码来自https://github.com/mirage/mirage-tcpip/blob/master/src/ipv4/ipv4_packet.ml
【问题讨论】:
-
这能回答你的问题吗? OCaml |> operator
标签: functional-programming ocaml