15

I am looking for a code formatter or pretty printer for ocaml. Something like gofmt for the go programming language. It should preferably preserve comments.

I am correcting hand-ins and some of the code is formatted in a way that makes it very hard to read.

ReyCharles
  • 1,772
  • 10
  • 30

1 Answers1

18

if you don't care about comments, you can use camlp4:

camlp4 <file> -parser o -printer o > <new-file>

Or you can use external indenter tools, as ocp-indent.

Thomas
  • 5,047
  • 19
  • 30