Your pack_aux
is not tail recursive (acc :: pack_aux [b] tl
is not a tail call).
In exchange you get to avoid having the List.rev
in the other solution.
It’s a similar difference as the usual
let rec non_tailrec_map f = function
| [] -> []
| x :: tl ->
let fx = f x in
fx :: non_tailrec_map f tl
(* vs *)
let tailrec_map f l =
let rec aux acc = function
| [] -> acc
| x :: tl -> aux (f x :: acc) tl
in
List.rev (aux [] l)