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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With