
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

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
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@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

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 Yes, that's exactly my concern.
Why do you want this? I'm working on #7282 - RebindableSyntax and Arrows. Here's a snippet from desugaring of arrow notation:
leaves = concatMap leavesMatch matches where leavesMatch :: LMatch Id (Located (body Id)) -> [(Located (body Id), IdSet)] leavesMatch (L _ (Match pats _ (GRHSs grhss binds))) = let defined_vars = mkVarSet (collectPatsBinders pats) `unionVarSet` mkVarSet (collectLocalBinders binds) in [(body, mkVarSet (collectLStmtsBinders stmts) `unionVarSet` defined_vars) | L _ (GRHS stmts body) <- grhss] This is in the desugarer. But I need to also know `length leaves` at the renaming stage, which means I need to call `concatMap leavesMatch matches`. The problem is that in the renamer my datatypes are not parametrised by `Id`. I turned `Id` into a type parameter `id`, but then I can't use VarSets. I could use more general UniqueSets but only if `id` type parameter is an instance of Uniquable. And since in the renamer the datatypes are parametrized with RdrName this leads me to wanting Uniqable RdrName instance. Janek

FYI it's #7828, not #7282.
Jan, I'm very glad you're working on this. Thanks!
On Mon, Jun 16, 2014 at 2:33 PM, Jan Stolarek
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 Yes, that's exactly my concern.
Why do you want this? I'm working on #7282 - RebindableSyntax and Arrows. Here's a snippet from desugaring of arrow notation:
leaves = concatMap leavesMatch matches where leavesMatch :: LMatch Id (Located (body Id)) -> [(Located (body Id), IdSet)] leavesMatch (L _ (Match pats _ (GRHSs grhss binds))) = let defined_vars = mkVarSet (collectPatsBinders pats) `unionVarSet` mkVarSet (collectLocalBinders binds) in [(body, mkVarSet (collectLStmtsBinders stmts) `unionVarSet` defined_vars) | L _ (GRHS stmts body) <- grhss]
This is in the desugarer. But I need to also know `length leaves` at the renaming stage, which means I need to call `concatMap leavesMatch matches`. The problem is that in the renamer my datatypes are not parametrised by `Id`. I turned `Id` into a type parameter `id`, but then I can't use VarSets. I could use more general UniqueSets but only if `id` type parameter is an instance of Uniquable. And since in the renamer the datatypes are parametrized with RdrName this leads me to wanting Uniqable RdrName instance.
Janek _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

would making arrow remindable involve dropping the arr == haksell functions
assumption or doing something that would allow generalized arrows?
On Mon, Jun 16, 2014 at 5:14 PM, Nicolas Frisby
FYI it's #7828, not #7282.
Jan, I'm very glad you're working on this. Thanks!
On Mon, Jun 16, 2014 at 2:33 PM, Jan Stolarek
wrote: 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 Yes, that's exactly my concern.
Why do you want this? I'm working on #7282 - RebindableSyntax and Arrows. Here's a snippet from desugaring of arrow notation:
leaves = concatMap leavesMatch matches where leavesMatch :: LMatch Id (Located (body Id)) -> [(Located (body Id), IdSet)] leavesMatch (L _ (Match pats _ (GRHSs grhss binds))) = let defined_vars = mkVarSet (collectPatsBinders pats) `unionVarSet` mkVarSet (collectLocalBinders binds) in [(body, mkVarSet (collectLStmtsBinders stmts) `unionVarSet` defined_vars) | L _ (GRHS stmts body) <- grhss]
This is in the desugarer. But I need to also know `length leaves` at the renaming stage, which means I need to call `concatMap leavesMatch matches`. The problem is that in the renamer my datatypes are not parametrised by `Id`. I turned `Id` into a type parameter `id`, but then I can't use VarSets. I could use more general UniqueSets but only if `id` type parameter is an instance of Uniquable. And since in the renamer the datatypes are parametrized with RdrName this leads me to wanting Uniqable RdrName instance.
Janek _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

FYI it's #7828, not #7282. Of course, yes.
would making arrow remindable involve dropping the arr == haksell functions assumption or doing something that would allow generalized arrows? Not sure if I fully understand what you mean. There's an idea to give up on current desugaring that heavily uses arr, >>> etc. in favor of desugaring based on bind equivalents for arrows. Is this what you wanted to know? There's some discussion on the Trac you might want to follow.
Janek

So, without really trying to understand the code, what you are saying is this: you want a finite map from RdrNames. That seems sensible enough, if the domain elements all appear in the same scope in the Haskell source. I don't have enough perspective to say whether a Uniquable instance is the way to get to a finite map here.
Richard
On Jun 16, 2014, at 3:33 PM, Jan Stolarek
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 Yes, that's exactly my concern.
Why do you want this? I'm working on #7282 - RebindableSyntax and Arrows. Here's a snippet from desugaring of arrow notation:
leaves = concatMap leavesMatch matches where leavesMatch :: LMatch Id (Located (body Id)) -> [(Located (body Id), IdSet)] leavesMatch (L _ (Match pats _ (GRHSs grhss binds))) = let defined_vars = mkVarSet (collectPatsBinders pats) `unionVarSet` mkVarSet (collectLocalBinders binds) in [(body, mkVarSet (collectLStmtsBinders stmts) `unionVarSet` defined_vars) | L _ (GRHS stmts body) <- grhss]
This is in the desugarer. But I need to also know `length leaves` at the renaming stage, which means I need to call `concatMap leavesMatch matches`. The problem is that in the renamer my datatypes are not parametrised by `Id`. I turned `Id` into a type parameter `id`, but then I can't use VarSets. I could use more general UniqueSets but only if `id` type parameter is an instance of Uniquable. And since in the renamer the datatypes are parametrized with RdrName this leads me to wanting Uniqable RdrName instance.
Janek

I would require a lot of convincing that we wanted Uniques for RdrNames. I seriously doubt that, once the dust has settled, you'll need a finite map indexed by RdrNames. But even if you do, you could use a TrieMap-like structure.
Simon
| -----Original Message-----
| From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of Richard
| Eisenberg
| Sent: 17 June 2014 15:01
| To: Jan Stolarek
| Cc: ghc-devs@haskell.org
| Subject: Re: Uniquable RdrName instance
|
| So, without really trying to understand the code, what you are saying is
| this: you want a finite map from RdrNames. That seems sensible enough, if
| the domain elements all appear in the same scope in the Haskell source. I
| don't have enough perspective to say whether a Uniquable instance is the
| way to get to a finite map here.
|
| Richard
|
| On Jun 16, 2014, at 3:33 PM, Jan Stolarek

On 17/06/14 20:53, Simon Peyton Jones wrote:
I would require a lot of convincing that we wanted Uniques for RdrNames. I seriously doubt that, once the dust has settled, you'll need a finite map indexed by RdrNames. But even if you do, you could use a TrieMap-like structure.
I must be missing something... but what's wrong with Map RdrName? Cheers, Simon
Simon
| -----Original Message----- | From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of Richard | Eisenberg | Sent: 17 June 2014 15:01 | To: Jan Stolarek | Cc: ghc-devs@haskell.org | Subject: Re: Uniquable RdrName instance | | So, without really trying to understand the code, what you are saying is | this: you want a finite map from RdrNames. That seems sensible enough, if | the domain elements all appear in the same scope in the Haskell source. I | don't have enough perspective to say whether a Uniquable instance is the | way to get to a finite map here. | | Richard | | On Jun 16, 2014, at 3:33 PM, Jan Stolarek
wrote: | | >> 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 | > Yes, that's exactly my concern. | > | >> Why do you want this? | > I'm working on #7282 - RebindableSyntax and Arrows. Here's a snippet | from desugaring of arrow | > notation: | > | > leaves = concatMap leavesMatch matches | > where | > leavesMatch :: LMatch Id (Located (body Id)) -> [(Located (body Id), | IdSet)] | > leavesMatch (L _ (Match pats _ (GRHSs grhss binds))) | > = let defined_vars = mkVarSet (collectPatsBinders pats) | `unionVarSet` | > mkVarSet (collectLocalBinders | binds) | > in [(body, mkVarSet (collectLStmtsBinders stmts) | `unionVarSet` defined_vars) | L _ | > (GRHS stmts body) <- grhss] | > | > This is in the desugarer. But I need to also know `length leaves` at | the renaming stage, which | > means I need to call `concatMap leavesMatch matches`. The problem is | that in the renamer my | > datatypes are not parametrised by `Id`. I turned `Id` into a type | parameter `id`, but then I | > can't use VarSets. I could use more general UniqueSets but only if `id` | type parameter is an | > instance of Uniquable. And since in the renamer the datatypes are | parametrized with RdrName this | > leads me to wanting Uniqable RdrName instance. | > | > Janek | | _______________________________________________ | ghc-devs mailing list | ghc-devs@haskell.org | http://www.haskell.org/mailman/listinfo/ghc-devs _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

We just haven't needed one so far. Can a RdrName and a Name have the same Unique? Well, of course that just depends on what you are using the RdrName Uniques for. It's not a question that has a yes or no answer. Does it matter if (Orig m x) and (Orig n x) have the same Unique? Same answer, except that I bet the answer is "yes it matters". FWIW the "OrigNameCache" is a finite map keyed by (ModuleName,Orig) pairs. Simon | -----Original Message----- | From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of Jan | Stolarek | Sent: 16 June 2014 12:45 | To: ghc-devs@haskell.org | Subject: Uniquable RdrName instance | | 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@haskell.org | http://www.haskell.org/mailman/listinfo/ghc-devs
participants (6)
-
Carter Schonwald
-
Jan Stolarek
-
Nicolas Frisby
-
Richard Eisenberg
-
Simon Marlow
-
Simon Peyton Jones