是否有 OCaml 工具支持使用 Perl 的 Perl::Critic 模块等最佳实践?

发布于 2024-10-10 17:26:18 字数 265 浏览 0 评论 0原文

是否存在一种工具可以分析 OCaml 程序并提出风格和代码方面的一些改进建议?在 Perl 的世界里仍然存在 Perl::Critic 避免不良风格。

我需要的是一些工具,这些工具不仅可以提示样式,还可以使事情变得更清晰,并避免 OCaml 程序中非尾递归的构造。

有什么提示吗?

Does there exist a tool which analyzes OCaml programs and suggests some improvements in style and code? In the world of perl there still exists Perl::Critic to avoid bad style.

What I need are some tools which make hints not only about style but also to make things cleaner and to avoid constructs which are not tail recursive in OCaml programs.

Any hints?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌若浮生 2024-10-17 17:26:18

我没有使用过它,但上周有关 Caml 群组的消息提到吉祥物。它看起来就是你所追求的。我不确定尾递归标准;上述项目的作者没有提到它们,但提到了插件功能。

或者,使用 -dlinear (对于 ocamlopt[.opt])进行编译将生成线性化代码,其中提及该函数是否是尾调用。 -annot 也会产生尾部调用信息,但除了 变更日志(在 3.11.0 中添加)。它以什么方式标记尾部调用,它不会做相反的标记非尾部调用(或者也许有办法?)。下面是一个名为 sum 的函数的输出示例,

let rec sum a = function
    | x when x = 0 -> a
    | x -> sum (a+1) (x-1)

它产生(以及更多输出),

*** Linearized code
camlTail__sum_58:
  if x/30[%rbx] !=s 1 goto L100
  return R/0[%rax]
  L100:
  I/31[%rbx] := I/31[%rbx] + -2
  I/32[%rax] := I/32[%rax] + 2
  tailcall "camlTail__sum_58" R/0[%rax] R/1[%rbx]

但我认为经验将是您最好的选择。查看一些流行的项目(例如电池),了解风格和典型惯例。我不认为插件会帮助您调用累加器变量 acc 或延续 cont

I have not used it but a message on the Caml Groups last week mentions Mascot. It looks to be what you are after. I'm not sure about the tail-recursion criteria; the author of the above project doesn't mention them, but does mention plugin capabilities.

Alternatively, compiling with -dlinear (for ocamlopt[.opt]) will produce linearized code that mentions if the function is a tail-call. -annot also produces tail-call information, but I cannot find a reference aside from the changelog (it was added in 3.11.0). What way it does tag tail-calls, it doesn't do the converse, tag non-tail calls (or maybe there is a way?). Below is an example of the output for a function called sum,

let rec sum a = function
    | x when x = 0 -> a
    | x -> sum (a+1) (x-1)

produces (amongst much more output),

*** Linearized code
camlTail__sum_58:
  if x/30[%rbx] !=s 1 goto L100
  return R/0[%rax]
  L100:
  I/31[%rbx] := I/31[%rbx] + -2
  I/32[%rax] := I/32[%rax] + 2
  tailcall "camlTail__sum_58" R/0[%rax] R/1[%rbx]

I think experience is going to be your best bet though. Look through some popular projects (Batteries, for example) to get a feel for style and typical conventions. I don't think a plugin is going to help you call your accumulator variables acc or continuations cont.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文