title: union of list in ocaml without using library
body: <p>I have a assignment which requires writing a code to union list without using any library functions
  this is my code</p>
  
  <pre><code>let rec union (l1:'a list) (l2:'a list) =
    let rec f x l = match l with
      | [] -&gt; true
      | hd::tl -&gt;
        if x = hd then false else f x tl
     in
    match l2 with
    | [] -&gt; l1
    | hd::tl -&gt;
      if f hd l1 then
        union hd::l1 tl
      else
        union l1 tl
  </code></pre>
  
  <p>but the compiler said that "This expression has type 'a but an expression was expected of type 'a list The type variable 'a occurs inside 'a list"</p>
  
  <p>can somebody helps me to find out where did I do wrong? thanks</p>