title: OCaml pattern matching on builtin types
body: <p>I'm trying to write a polymorphic function, which needs to do something slightly different depending on the type of the parameter.  Is there any way that I can do a pattern match on the type of the object, using the builtin types?  I'm thinking of something along these lines:</p>
  
  <pre><code>let to_string v =
      match v with
      | string -&gt; v
      | int -&gt; string_of_int v
      | _ -&gt; ""
  </code></pre>
  
  <p>but this doesn't seem to be a valid OCaml program.</p>
  
  <p>I have seen <a href="https://stackoverflow.com/questions/633200/determining-type-on-the-fly-in-ocamls-oop-construct">this question</a>, but that doesn't quite answer my question either.  I would <em>prefer</em> to use the standard,builtin types rather than constructing new types for this (although I can do that if that is the only way).</p>