let fold_lefti ~f acc str = 
    let r = ref acc in
    for i = 0 to (String.length str - 1) do
      r := f !r i str.[i]
    done;
    !r