Binding again

"Simon Peyton-Jones" <[email protected]>
Newsgroups gmane.comp.lang.haskell.template
Message-ID <036EAC76E7F5EC4996A3B3C3657D4116012C9C35@EUR-MSG-21.europe.corp.microsoft.com>
In looking into my TH bug stack, I've found the following question.
Suppose we have

d1 :: Q [Dec]
d1 = return [FunD (mkName "f") ...]

d2 :: Q [Dec]
d2 = do { fn <- newName "f"; return [FunD fn ...] }

QUESTION 1: is this OK:

	$d1
	h = f 3

QUESTION 2: What about this?

	$d2
	h = f 3

The answer to Q1 must presumably be 'yes', but what about Q2.  "newName"
generates a fresh name, to be sure, but does it bind the 'f' in the
subsequent declaration.

I think the answer is probably 'yes'.  COnsier
	[| \x -> f $(dyn "x") |]

Here I think we all agree the $(dyn "x") picks up the binding for 'x',
even though the binding must be generated with newName.  And (returning
to Q2), the "top-level splice hack" treats everything following the
top-level splice as if it were (dyn "f") stuff.

But a 'yes' to Q2 might be considered inconvenient, because you might
generate lots of (newName "f"), and they'd then clash.

Views?

Simon
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.