title: Merging two lists in F#
body: <p>I wrote this function which merges two lists together but as I'm fairly new to functional programming I was wondering whether there is a better (simpler) way to do it?</p>
  
  <pre><code>let a = ["a"; "b"; "c"]
  let b = ["d"; "b"; "a"]
  
  let merge a b =
      // take all a and add b
      List.fold (fun acc elem -&gt; 
                       let alreadyContains = acc |&gt; List.exists (fun item -&gt; item = elem)
                       if alreadyContains = true then
                          acc
                       else 
                          elem :: acc |&gt; List.rev
                       ) b a                
  
  let test = merge a b 
  </code></pre>
  
  <p>Expected result is: ["a"; "b"; "c"; "d"], I'm reverting the list in order to keep the original order. I thought I would be able to achieve the same using List.foldBack (and dropping List.rev) but it results in an error:</p>
  
  <p>Type mismatch. Expecting a
      'a<br>
  but given a
      'a list<br>
  The resulting type would be infinite when unifying ''a' and ''a list'</p>
  
  <p>Why is there a difference when using foldBack? </p>