[Template-haskell] Binding again

Simon Peyton-Jones simonpj at microsoft.com
Thu Nov 25 09:06:27 EST 2004


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



More information about the template-haskell mailing list