Comparing StableNames of different type
Edward Kmett
ekmett at gmail.com
Tue Aug 28 20:07:28 CEST 2012
On Tue, Aug 28, 2012 at 12:08 PM, Nicolas Frisby
<nicolas.frisby at gmail.com>wrote:
> On Tue, Aug 28, 2012 at 3:34 AM, Simon Marlow <marlowsd at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20120828/66df294d/attachment.htm>
More information about the Glasgow-haskell-users
mailing list