Printing unit list after the output

let rec rev_list ls rls =
match ls with
| [] → rls
|h::t → rev_list t rls@[h];;

let p = fun thing → Printf.printf "%i " thing;;

let rec choose’ etc’ things k =
match things with
| [] → k []
| x :: xs → choose’ etc’ xs (fun t ->k (etc’ x :: t))
let choose etc things = choose’ etc (rev_list things []) Fun.id;;

choose (fun thing → Printf.printf "%i " thing) [1;2] ;;

output is
1 2 - : unit list = [(); ()]
i just want 1 2. can someone help please.

That’s because you are typing in the toplevel. To stop using the toplevel, save your code to some_file.ml and run it like this: ocaml some_file.ml

2 Likes

Adding to what Juloo said–note that when you save OCaml source in a file and run it from there, you don’t need ;;.