I feel like 100 questions like this have already been asked, but I can't determine the answer from them: I learned the following Haskell (7.8.4) trick:
type family Equal2 (a :: k) (b :: k) :: Bool where
Equal2 a a = True
Equal2 a b = False
which can be used to compile code separately depending on whether "a ~ b".
Is it possible to extend this technique to other constraints like matching a typeclass? It feels like it's close to being possible, but not quite there.
constraints
package. It isn't exactly the same as what you're talking about but, depending on what you need it for, it might be enough. – David Young