#5398: Multiple declarations of uniquely generated name
-------------------------------+--------------------------------------------
Reporter: basvandijk | Owner:
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Template Haskell | Version: 7.0.4
Resolution: invalid | Keywords:
Testcase: | Blockedby:
Difficulty: | Os: Unknown/Multiple
Blocking: | Architecture: Unknown/Multiple
Failure: None/Unknown |
-------------------------------+--------------------------------------------
Changes (by simonpj):
* status: new => closed
* resolution: => invalid
Comment:
We had a discussion at !CamHac which concluded that PLAN B is indeed the
right one. A principled reason for this is the identity
{{{
$[| e |] = e
}}}
For this to hold we need that
{{{
$[| \x -> $(return (VarE (mkName "x"))) |]
=
\x -> $(return (VarE (mkName "x")))
}}}
In the latter, the `(mkName "x")` must clearly bind to the lambda. And so
it must do so in the former too.
Concerning the SYB story, you just have to generate fresh names for the
top level bindings. You can do that by name-mangling the type involved
(which is I believe how you fixed it) -- but it's also possible to write a
function
{{{
mangleName :: Name -> Name
mangleName name@(Name occ fl)
= case fl of
NameU u -> Name (mangle_occ occ u) fl
_ -> name
where
mangle_occ :: OccName -> Int# -> OccName
mangle_occ occ uniq = mkOccName (occNameString occ ++ "-" ++ show (I#
uniq))
}}}
This will take a `Name` built with `newName` (which generates a `NameU`),
and incorporate the unique in the string-name of the `Name`.
It might even be worth adding this to TH's API, but I'll wait to see how
useful it is first.
It's also worth noting that what you ''really'' wanted for SYB was a kind
of anonymous local module. You really want your splice to expand thus:
{{{
$(derive 'T)
=======> expands to
module () where
constr = ...
dataType ...
instance (..blah..) => Data ctx ByteString where
...constr...dataType...
}}}
so that the definitions of `constr` and `dataType` are not visible in the
outer scope.
But that is another story! I'll open a ticket for it, and close this as
invalid.
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5398#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs