RosettaCodeData/Task/Repeat-a-string/OCaml/repeat-a-string-1.ocaml

9 lines
272 B
Plaintext

let string_repeat s n =
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 (* not stricly necessary, the bytes type is equivalent to string except mutability *)
;;