TH naming problem, different 'newName's clash
Duncan Coutts
duncan.coutts at worcester.oxford.ac.uk
Mon Mar 8 10:06:38 EST 2004
I'm using the new abstract names of TH2 in ghc 6.3 (CVS early March)
I'm generating code that looks like this:
let foo_1 = e1
foo_2 = e2
in e3
I'm using
name <- newName "foo"
to generate these names (foo_1, foo_2 etc) however when I splice this
code in ghc complains as if I'd written
let foo = e1
foo = e2
in e3
ie that I have multiple definitions of the same variable in the same let
block.
So, to be precise:
foo :: ExpQ
foo = do
foo1 <- newName "foo"
foo2 <- newName "foo"
letE [valD (varP foo1) (normalB [| 3 |]) []
,valD (varP foo2) (normalB [| 4 |]) []]
[| 5 |]
If we print this, it looks like what we want:
> do {e <- runQ foo; print (pprExp 0 e)}
let foo_0 = 3
foo_1 = 4
in 5
but if we ask about $(foo), ghc tells us:
Conflicting definitions for `foo'
In the binding group for: foo, foo
It looks like the unique identifiers on the local names are being
forgotten when we splice in.
I can work around this for the moment using something like
mkName ("foo_" ++ show somethingUnique)
but it's not nice.
Duncan
More information about the Glasgow-haskell-bugs
mailing list