【发布时间】:2023-04-10 12:44:01
【问题描述】:
在the book Real World OCaml,我找到了这段代码:
let command =
Command.basic
~summary:"Generate an MD5 hash of the input data"
Command.Spec.(
empty
...
+> anon (maybe_with_default "-" ("filename" %: file))
)
(fun use_string trial filename () ->
我在最后一行看到() (fun use_string trial filename ())。
同样来自Print a List in OCaml,我在第一场比赛中也看到了()。
let rec print_list = function
[] -> ()
| e::l -> print_int e ; print_string " " ; print_list l
那么,() 在这两种情况下是什么意思呢? lambda 表达式 (fun) 如何在其参数列表中包含 ()?
【问题讨论】:
-
最接近的类比是 C 中的
void类型。但在类型理论上存在细微但重要的区别。