let foldi t ~init ~f = let res = ref init in for i = 0 to length t - 1 do res := f i !res (B. get t i); done; !res