OCaml复杂名称重用与递归函数.混乱

mar*_*ver 1 ocaml

我正在阅读一些示例并遇到此代码,谷歌让我失望.

let id = fun x -> x in fun x -> if x> 0 then id [] else (id x) :: [];;
- : int -> int list = <fun>
Run Code Online (Sandbox Code Playgroud)

正如Caml告诉我们的那样,这被证明是一般的功能.

但它有"let"而不是"let rec",而功能名称id在功能体中出现了好几次.

这看起来不合逻辑.

所以我在想

1. is this actually a recursive function? 

2. Or they just happen to be different types reusing the same name confusingly. 
Run Code Online (Sandbox Code Playgroud)

你能用明确的理由站在具体的基础上,展示你富有洞察力的想法吗?

sep*_*p2k 5

代码中有两个函数.第一个是fun x -> x.这个功能是不是递归(它只是返回x不变,而不调用任何其它功能,包括自身),它被命名为id使用let.

另一个功能是fun x -> if x > 0 then id [] else (id x) :: [].此功能没有名称.它也不是递归的,因为它调用的唯一函数是id并且id不会回调它.

该名称id不会在此代码中重复使用.它只用于指代该功能fun x -> x.正在重用的唯一名称是x:在id它的定义中用于引用id的参数,在其他函数的定义中,它用于引用该函数的参数.