有没有办法让OCaml告诉我一个函数是否使用尾递归实现?我不是指阅读代码。我的意思是让OCaml告诉我,就像这样:
let x = tail_recursion f;;
您可以使用“-annot”编译源代码。这将生成一个注释文件,一些编辑器可以使用。
在caml-mode (emacs)中的命令是:
M-x caml-types-show-call
ocamlc -annot foo.ml
foo.annot
foo.ml
"test.ml" 1 0 19 "test.ml" 1 0 22\ncall(\n tail\n)
ocamlc -annot foo.ml
应该生成foo.annot
,除非存在类型错误。(如果foo.ml
依赖其他模块,则需要像往常一样传递它们。) - gsg"test.ml" 1 0 19 "test.ml" 1 0 22\ncall(\n tail\n)
的条目。请注意,这指的是源文件中调用点(而不是函数定义)的文本范围。我不确定是否有任何独立于编辑器的工具来解析此信息,因为我只使用emacs。 - gsg