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