let init n ~f = if n < 0 then [] else let rec loop i accum = assert (i >= 0); if i = 0 then accum else loop (i-1) (f (i-1) :: accum) in loop n []