Tutorial: How to trace a function in OCaml
Posted on In QATutorial: How to trace a function in OCaml.
Use #trace
. For example, to trace function f
:
# let rec f n = if n = 0 then 1 else f (n - 1) * n;;
val f : int -> int = <fun>
# #trace f;;
f is now traced.
# f 4;;
f <-- 4
f <-- 3
f <-- 2
f <-- 1
f <-- 0
f --> 1
f --> 1
f --> 2
f --> 6
f --> 24
- : int = 24