This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* note that in order to preserve certain order | |
and also show the conciseness of the implementation, | |
no tail-recursive is used *) | |
let ins_all_positions x l = | |
let rec aux prev acc = function | |
| [] -> (prev @ [x]) :: acc |> List.rev | |
| hd::tl as l -> aux (prev @ [hd]) ((prev @ [x] @ l) :: acc) tl | |
in | |
aux [] [] l | |