| Newsgroups |
gmane.comp.lang.ocaml.beginners |
| Message-ID |
<[email protected]> |
Thank you for your feedback. It helped me a lot ! In reality, using String.concat is not that hard (see the relatively short&simple code below), you just have to be careful a little bit about the order of the operations.
I was amazed by the efficiency of that solution : it executes my initial computation in less than a second!
let adjacent_elements_pair_list l=
let rec sub_f=
(function (accu,a,rl)->match rl with
[]->List.rev(accu)
|b::x->sub_f((a,b)::accu,b,x)
) in
match l with
[]->[]
|u::v->sub_f([],u,v);;
let interval s a b=String.sub s (a-1) (b-a+1);;
let insert_at_points s l=
let n=String.length s in
let temp1=(n,"")::(List.rev_append l [0,""]) in
let temp2=adjacent_elements_pair_list temp1 in
let temp3=List.rev_map (fun ((j2,w2),(j1,w1))->(interval s (j1+1) j2)^w2) temp2 in
String.concat "" temp3;;
let example= insert_at_points "123456789" [3,"aaa";6,"bb"];;