Having string slices can enable functions like String.trim
, String.take
and String.drop
(the latter two are not present in the OCaml stdlib tho) to work in constant time which is pretty neat.
However, in GC’ed languages, there’s a common problem with slices where a tiny slice (even 1 byte) to a huge string/bytes array prevents GC from collecting the entire huge string/bytes array. Therefore, the slices abstraction unfortunately leaks and requires careful thinking about memory usage in each case.