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