On Tue, Aug 28, 2012 at 12:08 PM, Nicolas Frisby
<nicolas.fri...@gmail.com>wrote:

> On Tue, Aug 28, 2012 at 3:34 AM, Simon Marlow <marlo...@gmail.com> wrote:
> >>>> On 24/08/2012 07:39, Emil Axelsson wrote:
> >>>>>
> >>>>> Are there any dangers in comparing two StableNames of different type?
> >>>>>
> >>>>>    stEq :: StableName a -> StableName b -> Bool
> >>>>>    stEq a b = a == (unsafeCoerce b)
> >>>>
> > Ok, I've added it.  It will be in GHC 7.8.1.
> >
> > Cheers,
> >         Simon
>
> Might we benefit from having a variant that returns Maybe (a :=: b)?
> Is that safe? I have limited experience with StableNames, but that
> intuitively seems safe. But polymorphism and references deserve more
> thought than I've given this yet.
>
> I'm referring to "data (:=:) :: * -> * -> * where Refl :: (a :=: a)",
> just to be clear.
>
>
No.

You can't safely determine that  a ~ b given that two stablenames are equal.

If you give Nothing a stableName, it'll have one stable name, regardless of
if you use it as a Maybe Int or a Maybe Bool. Maybe Int and Maybe Bool are
clearly not equal. This is admittedly an implementation detail. GHC would
be perfectly within its rights (if somewhat silly) to construct a fresh
Nothing every time, but it doesn't.

The reasoning you applied only works for fully monomorphic types.

 -Edward
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to