title: Trying to replicate the elements in a list n times in OCaml
body: <p>I'm trying to write a function that would take an input like :</p>
  
  <blockquote>
    <p>repeat 3 [1;2] ;;</p>
  </blockquote>
  
  <p>and display something like:</p>
  
  <blockquote>
    <p>[1;2;1;2;1;2] </p>
  </blockquote>
  
  <p>Now the code I have is: </p>
  
  <pre><code>let repeat ls n =
       let rec helper acc n l =
         if n = 0 then acc else helper (l :: acc) (n-1) l in
       let rec helper2 acc = function
         | [] -&gt; acc
         | h :: t -&gt; helper2 (helper acc n h) t  in helper2 [] (List.rev ls);;
  </code></pre>
  
  <p>which gives me an output of:</p>
  
  <pre><code>[1;1;1;2;2;2] 
  </code></pre>
  
  <p>for the same input. What can I do to fix this?</p>