Uniquable RdrName instance

Richard Eisenberg eir at cis.upenn.edu
Mon Jun 16 13:52:51 UTC 2014


Without looking into the precise details, this looks dangerous to me. Why do you want this? The danger I see lurking is that you might find two RdrNames that give the same answer to getUnique but represent different things:

foo x = x + (\x -> x) 3

I see two `x`s there that will have the same Unique attached to their RdrNames but will be very different. In fact, I'm surprised that OccName has a Uniquable instance, which seems similarly dangerous to me.

Richard

On Jun 16, 2014, at 7:45 AM, Jan Stolarek <jan.stolarek at p.lodz.pl> wrote:

> Hi all,
> 
> I just found myself in the need of Uniquable instance for RdrName. I'm surprised that such 
> instance does not exist already because other datatypes like Name or OccName already have 
> Uniquable instances. So, is there a reason why Uniquable instance for RdrName does not exist 
> already (other than "it wasn't needed")? How should such an instance look like? I made an 
> attempt:
> 
> rdrNameUnique :: RdrName -> Unique
> rdrNameUnique (Unqual occName) = getUnique occName
> rdrNameUnique (Qual _ occName) = getUnique occName
> rdrNameUnique (Orig _ occName) = getUnique occName
> rdrNameUnique (Exact name    ) = getUnique name
> 
> But I suspect this might be wrong:
> - cases 1 and 4 simply return a Unique for the OccName/Name stored inside RdrName. I think this 
> will assign the same Unique to RdrName and corresponding OccName/Name. Is this allowed?
> - cases 2 and 3 ignore the Module stored inside RdrName. Again, this assigns the RdrName with a 
> Unique identical to OccNames stored inside it.
> 
> Help appreciated.
> 
> Janek
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://www.haskell.org/mailman/listinfo/ghc-devs



More information about the ghc-devs mailing list