title: Appending two lists
body: <p>So this is one way to append two lists:</p>
  <pre><code>let rec append l1 l2 =
    match l1 with
    | h :: t -&gt; h :: append t l2
    | [] -&gt; l2
  </code></pre>
  <p>But I am trying to write  a tail-recursive version of append. (solve the problem before calling the recursive function).</p>
  <p>This is my code so far, but when I try to add append in the first if statement the code becomes faulty for weird reasons.</p>
  <pre><code>let list1 = [1;2;3;4]
  let list2 = [5;6;7;8]
  
  
  
  let rec append lista listb =
    match listb with
    | h :: taillist -&gt; if taillist != []  then 
    begin 
      lista @ [h];
      (* I cant put an append recursive call here because it causes error*)
    end else
    append lista taillist;
   | [] -&gt; lista;;
  
  
  append list1 list2;;
  </code></pre>