我见过一些实现如下:
let rec fact =
fun n ->
if n <= 0 then 1 else n * fact (n - 1)
另一种实现是:
let rec fact n =
if n <= 0 then 1 else n * fact (n - 1)
谁能告诉我这两种风格之间是否有任何区别?
最佳答案
这些定义是等价的。符号
let rec f a b c = <expr>
是一种方便的写作方式(语法糖):
let rec f = fun a b c -> <expr>
您可以在 section 6.7.1 of the OCaml manual 中找到它的描述,在本地定义标题下。
关于function - OCaml 中的这两个函数定义有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8697530/