Is it possible to place an inequality constraint on the typevariables of a function, à la foo :: (a ~ b) => a -> b as in GHC type family docs, except inequality rather than equality?
I realise that there is possibly no direct way to do this (as the ghc docs doesn’t list any to my knowledge), but I would be almost puzzled if this weren’t in some way possible in light of all the exotic type-fu I have been exposed to.
First, keep in mind that distinct type variables are already non-unifiable within their scope–e.g., if you have
\x y -> x, giving it the type signaturea -> b -> cwill produce an error about not being able to match rigid type variables. So this would only apply to anything calling the function, preventing it from using an otherwise simple polymorphic function in a way that would make two types equal. It would work something like this, I assume:Personally I doubt this would really be useful–the independence of type variables already prevents generic functions from collapsing to something trivial, knowing two types are unequal doesn’t actually let you do anything interesting (unlike equality, which lets you coerce between the two types), and such things being declarative rather than conditional means that you couldn’t use it to distinguish between equal/unequal as part of some sort of specialization technique.
So, if you have some specific use in mind where you want this, I’d suggest trying a different approach.
On the other hand, if you just want to play with ridiculous type-hackery…
Well, that was incredibly silly. Works, though: