let rec choose k xs =
  if k = 0 then [[]]
  else
    match xs with
    | [] -> []
    | h :: rest ->
      List.map (fun c -> h :: c) (choose (k - 1) rest)
      @ choose k rest

;;

List.length (choose 4 [1; 2; 3; 4; 5; 6; 7; 8; 9])
