是否有一个OCaml工具可以支持使用Perl的Perl :: Critic模块等最佳实践?(Is there an OCaml tool to support use of best practice

编程入门 行业动态 更新时间:2024-10-02 22:21:47
是否有一个OCaml工具可以支持使用Perl的Perl :: Critic模块等最佳实践?(Is there an OCaml tool to support use of best practices like Perl's Perl::Critic module?)

是否存在分析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?

最满意答案

我没有使用它,但上周在Caml团体上的消息提到了吉祥物 。 它看起来是你以后的样子。 我不确定尾递归标准; 上述项目的作者没有提及他们,但是提到了插件功能。

或者,使用-dlinear编译(对于ocamlopt[.opt] )将生成线性化代码,提到该函数是否是尾部调用。 -annot也-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或continuation 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.

更多推荐

本文发布于:2023-08-04 21:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1422235.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有一个   模块   工具   Perl   Critic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!