title: What's the closest thing to Haskell's typeclasses in OCaml?
body: <p>What are some ways that I can accomplish what Haskell's typeclasses do in OCaml? Basically, I want to write a polymorphic function without writing too much code. The typical way to do polymorphism is to supply an additional argument telling the function is what type it is currently working on. For example, let's say I want to sort a list of ints, I have to pass an additional comparator to the function.</p>
  
  
  
  <pre class="lang-ml prettyprint-override"><code>type comparison = Lesser | Equal | Greater
  
  my_sort : (a' -&gt; a' -&gt; comparison) -&gt; 'a list -&gt; 'a list
  </code></pre>
  
  <p>Is there anyway to tell OCaml that my type is comparable without writing a comparator function for every type that I want to sort? Which means that my sorting function would look just like this:</p>
  
  <pre class="lang-ml prettyprint-override"><code>my_sort : 'a list -&gt; 'a list
  </code></pre>