let rec foldi ~base ?(i=0) f l = match l with | [] -> base | x :: tail -> f i x ( foldi f ~base ~i:(i+1) tail )