let rev_mapi l ~f = let rec loop i acc = function | [] -> acc | h :: t -> loop (i + 1) (f i h :: acc) t in loop 0 [] l