let loop ~f ~acc ~start ~stop = assert (start <= stop); let rec aux acc = function | i when i = stop + 1 -> acc | i -> aux (f i acc) (i + 1) in aux acc start