title: How to determine data's constructor from foreign code?
body: <p>In my Haskell program i have an ADT with many constructors:</p>
  
  <pre><code>data MyData = Con1 |
      Con2 |
      ...
      Con20
  </code></pre>
  
  <p>I have an <code>foreign export ccall</code> function, which wraps <code>[MyData]</code> into array of <code>StablePtr's</code>. After calling it i need to determine which constructor have been used to construct each element.</p>
  
  <p>It could be solved this way</p>
  
  <pre><code>foreign export ccall getType :: StablePtr MyData -&gt; IO CInt
  getType (Con1) = return 1
  getType (Con2) = return 2
  ...
  </code></pre>
  
  <p>but then i would need to manually define these constants in C header. This is error-prone, so i wonder if there is a way to make GHC do this job for me.</p>