Anonymous user
Repeat a string: Difference between revisions
m
→{{header|OCaml}}
Line 1,686:
Since Ocaml 4.02 strings are immutable, as is convenient for a functional language. Mutable strings are now implemented in the module Bytes.
<lang ocaml>let string_repeat s n =
let s = Bytes.of_string s in
let len = Bytes.length s in
let res = Bytes.create (n * len) in
for i = 0 to pred n do
Bytes.blit s 0 res (i * len) len
done;
(Bytes.to_string res
;;</lang>
which gives the signature<lang ocaml>
testing in the toplevel:
|