How to debug OCaml code?

Can I find out how an experienced OCaml developer debugs his code?

What I am doing is just using Printf.printf . This is too troublesome as I have to comment on them all when I need a clean outlet.

What is the best way to control this debugging process? special annotation to enable or disable these logging ?

thanks

+6
source share
3 answers

You can use bolt for this purpose. This is an extension of the syntax.

Btw. Ocaml has a real debugger .

+7
source

There is an OCaml debugger function that you may not suspect of, which is usually not detected during stateful programming and is called time travel. See Section 16.4.4 . Basically, since all the information from step to step is stored on the stack, saving the changes associated with each step saved during processing, you can go through the changes in time to see the values ​​during this step. Think of it as starting a program after registering all the values ​​at each step in the data warehouse, and then indexing in this data warehouse based on the step number to see the values ​​at this stage.

+4
source

You can also use ocp-ppx-debug , which will add printf with a good location, rather than manually adding them.

 https://github.com/OCamlPro-Couderc/ocp-ppx-debug 
+2
source

Source: https://habr.com/ru/post/944610/


All Articles