Tracing an auxiliary function

Hello,
I’m a beginner in Ocaml and was just introduced to the #trace command to understand where my code fails,
Nethertheless, I can’t seem to make it work on auxiliary functions : let’s take a simple example :
let fibonacci n =
let rec aux acc1 acc2 = function
| i when i<n -> aux acc2 (acc1 + acc2) (i+1)
| | _ -> acc2
in aux 0 1 1
;;
How can I trace aux ? when I try
#trace fibonacci
fibonacci 55
I get :
fibonacci <-- 55
fibonacci --> 139583862445
- : int = 139583862445
which doesn’t tell me how the function executed…

The easiest way would be to first break it down to two separate functions :

let rec aux acc1 acc2 n = function
| i when i<n -> aux acc2 (acc1 + acc2) (i+1)
| | _ -> acc2
;;
let fibonacci n = aux 0 1 1 n;;
#trace aux;;

You can put the pieces back together when you are done debugging :slightly_smiling_face:

1 Like

That does work, thank you !