[Isaac, you need to join the TH list so you can post to it without me having to intervene.] | > genSummers n = returnQ [Fun ("makeSum" ++ (show i)) [Clause [] (Normal $(makeSum i)) [] ] | i | <- [1..n] ] | | But actually, I run into a stage restriction. You don't want a splice there! But if you remove it, (makeSum i) returns an ExpQ, whereas Normal wants an Exp. | > makeSumE :: Int -> Exp If you want to generate fresh (rather than fixed) variable names in makeSum, it definitely needs to return an ExpQ, not an Exp. An Exp is simply a data structure. An ExpQ (= Q Exp) is a monadic computation which can generate fresh names. Usually better. Your original makeSum looked better. | > genSummers n = returnQ [Fun ("makeSum" ++ (show i)) [Clause [] (Normal (makeSumE i)) [] ] | i | <- [1..n] ] if makeSum returns an ExpQ, you can't do this for the reason above. Solution: use the "smart constructors" from the paper. More like this: genSummers n = fun ("makeSum" ++ (show i)) [clause [] (normal (makeSum i)) [] ] Simon
participants (1)
-
Simon Peyton-Jones