title: How do you eliminate consecutive duplicates of list elements?
body: <p>(In Ocaml)</p>
  
  <p>This solution works</p>
  
  <pre><code>let compress l =
  let rec compress_2 l e =
      match l with
          | [] -&gt; [e]
          | h::t -&gt; if (h=e)
                      then (compress_2 t e)
                      else e::(compress_2 t)
  in
      match l with
          | [] -&gt; []
          | h::t -&gt; compress_2 t h;;
  </code></pre>
  
  <p>But why doesn't this solution work?</p>
  
  <pre><code>let rec compress (l: 'a list) : 'a list =
  match l with
      | [] -&gt; []
      | h::[] -&gt; [h]
      | h1::h2::t -&gt; if h1=h2 then h2::(compress t) else h1::h2::(compress t) ;;
  </code></pre>