Comparing StableNames of different type

Edward Kmett ekmett at
Fri Aug 24 16:10:05 CEST 2012

You can wind up with StableNames matching even when the types differ. Consider naming [] :: [Int] and [] :: [()]. This is harmless for most usecases.

I've used unsafeCoerce to compare StableNames on different types for years without problems.

Admittedly, I do find it a bit of an oddity that the type shows up in their signature at all. :)

Sent from my iPhone

On Aug 24, 2012, at 5:08 AM, Simon Marlow <marlowsd at> wrote:

> On 24/08/2012 07:39, Emil Axelsson wrote:
>> Hi!
>> Are there any dangers in comparing two StableNames of different type?
>>   stEq :: StableName a -> StableName b -> Bool
>>   stEq a b = a == (unsafeCoerce b)
>> I could guard the coercion by first comparing the type representations,
>> but that would give me a `Typeable` constraint that would spread
>> throughout the code.
> I think that's probably OK.  It should be safe even if the types are different, but I presume you expect the types to be the same, since otherwise the comparison would be guaranteed to return False, right?
> Cheers,
>    Simon
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at

More information about the Glasgow-haskell-users mailing list