let fold t ~init ~f = let res = ref init in for i = 0 to String.length t - 1 do res := f !res t.[i]; done; !res