title: Can I differentiate between typeclass instances at runtime?
body: <p>Is it possible to implement a type class as follows:</p>
  
  <pre><code>class SomeClass e where
      isEq :: (SomeClass e') =&gt; e -&gt; e' -&gt; Bool
  </code></pre>
  
  <p>where <code>isEq x y</code> would return true when <code>x</code> and <code>y</code> are both the same instance of this type class?</p>
  
  <p>Context: This is a thinly-veiled attempt at getting run-time type tests. While at first I read that Haskell has type erasure, I've also read that with recent extensions to GHC, some run-time information in there.</p>
  
  <p>edit: for those wondering about my usecase... I've been using type-level programming to ensure certain properties of some of my ADTs, namely involving resource usage. These resources are represented by distinct types (and resource locks are accordingly implemented at type level). </p>
  
  <p>I'm attempting to write an optimisation procedure that requires identification of resource writing/reading. But since all my resources are represented by distinct singletons, whose only common factor (apart from all values being bottom) is the typeclass which groupes them together. </p>
  
  <p>In a nutshell I want to use the results of my type-level programming at a run-time, value level.</p>