title: Why does OCaml have two sorting functions: List.sort and List.stable_sort?
body: <p>here are the doc:</p>
  
  <hr>
  
  <pre><code>val sort : ('a -&gt; 'a -&gt; int) -&gt; 'a list -&gt; 'a list
  </code></pre>
  
  <p>Sort a list in increasing order according to a comparison function. The comparison function must return 0 if its arguments compare as equal, a positive integer if the first is greater, and a negative integer if the first is smaller (see Array.sort for a complete specification). For example, compare is a suitable comparison function. The resulting list is sorted in increasing order. List.sort is guaranteed to run in constant heap space (in addition to the size of the result list) and logarithmic stack space.</p>
  
  <p>The current implementation uses Merge Sort. It runs in constant heap space and logarithmic stack space.</p>
  
  <pre><code>val stable_sort : ('a -&gt; 'a -&gt; int) -&gt; 'a list -&gt; 'a list
  </code></pre>
  
  <p>Same as List.sort, but <code>the sorting algorithm is guaranteed to be stable</code> (i.e. elements that compare equal are kept in their original order) .</p>
  
  <p>The current implementation uses Merge Sort. It runs in constant heap space and logarithmic stack space.</p>
  
  <hr>
  
  <p>I thought <code>merge sort</code> anyway is stable, right? </p>
  
  <p>How can OCaml produce a <code>non-stable merge</code> sort? </p>
  
  <p>In the <code>non-statble merge sort</code> version, is it faster?</p>