let rec concat ?(sep=empty) tl =
match tl with
| [] -> empty
| one :: more ->
begin try
let first_char =
try S.get one 0
with _ -> S.get sep 0
in
let sep_length = S.length sep in
let total_length =
List.fold_left ~init:(S.length one) more ~f:(fun prev s ->
prev + sep_length + S.length s) in
let dst = make total_length first_char in
let index = ref 0 in
blit ~dst ~dst_pos:!index ~src:one ~src_pos:0 ~len:(length one);
index := !index + (length one);
List.iter more ~f:(fun s ->
blit ~dst ~dst_pos:!index ~src:sep ~src_pos:0 ~len:sep_length;
index := !index + sep_length;
blit ~dst ~dst_pos:!index ~src:s ~src_pos:0 ~len:(length s);
index := !index + (length s);
);
dst
with _ ->
concat more ~sep
end