1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
let remove ~idx l =
let rec aux ~left ~right ~i =
match right with
| _ :: tl when i = idx -> List.rev_append left tl
| hd :: tl -> aux ~left:(hd :: left) ~right:tl ~i:(i + 1)
| [] -> l
in
aux ~left:[] ~right:l ~i:0
let rec permutations = function
| [] -> [ [] ]
| [ elm ] -> [ [ elm ] ]
| l ->
List.mapi
(fun idx elm ->
List.map (List.cons elm) (permutations @@ remove ~idx l))
l
|> List.flatten
let rewrite_field_name name =
if name.[0] = '_' then String.(sub name 1 (length name - 1)) else name