Feature Request: TypeLits function `cmpSymbol`
GHC.TypeLits module has a
sameSymbol function, which is great for checking equality of symbols at runtime. It also has a
CmpSymbol type family for comparing symbols at the type level. I feel like there should also be a
cmpSymbol function for comparing symbols at runtime.
I propose we add
GHC.TypeLits. The definition I had in mind is:
cmpSymbol :: (KnownSymbol a, KnownSymbol b) => Proxy a -> Proxy b -> Either (a :~: b) (Either (CmpSymbol a b :~: 'LT) (CmpSymbol a b :~: 'GT)) cmpSymbol x y = case compare (symbolVal x) (symbolVal y) of EQ -> Left (UNSAFE.unsafeCoerce Refl) LT -> Right (Left (UNSAFE.unsafeCoerce Refl)) GT -> Right (Right (UNSAFE.unsafeCoerce Refl))
The implementation here is very similar to the implementation of
sameSymbol, but if the symbols are not the same, the caller is provided with evidence of the fact.