let permute f l = List.map (fun i -> List.nth l (f i)) (indexes l)