John Lato wrote: >> Now, I have found another behavior difficult to understand for me: >> >> > runQ $ lift "u" >> ListE [LitE (CharL 'u') >> > runQ $ [| "u" |] >> LitE (StringL "u") >> >> So we have similar behaviors for lift and [||]. We can check it in a >> splice: >> >> > $( [| "u" |] ) >> "u" >> > $( lift "u" ) >> "u" >> >> But if I replace a working version: >> >> pr n = [| putStrLn ( $(lift( nameBase n ++ " = " )) ++ show $(varE n) ) >> |] ----- case (i) ----- >> >> by >> >> pr n = [| putStrLn ( $([| (nameBase n) ++ " = " |]) ++ show $(varE n) ) >> |] ----- case (ii) ----- >> >> I again get the error >> > > In the working version, 'n' appears inside a splice, whereas in the other > n > is in a quote. AFAIK any value can be used in a splice (provided it meets > the staging restrictions), whereas only Lift-able values can be used in a > quote.
If I take this as a granted axiom, then I can admit the behavior above (error in case (ii), whereas it is working in case (i)) because n is a (Name), and so is not instance of Lift. Thus we are compelled to use lift instead of [||] (although the behavior is about the same for both in simple examples, as shown in my example above for "u"). I do not understand the exact reason for that, but I can do without; and maybe it is better, because I am very probably not enough experienced to understand the details (and the reason is perhaps not trivial when I read Oleg who writes that what gives an error above in Haskell works in MetaOCaml). What is strange is that: * in the version using "lift", the definition of lift asks for the output of (nameBase n) to be an instance of Lift, what is the case because it is a string (cf my previous post in this thread). * whereas in the second version, we ask for n, not (nameBase n), to be an instance of Lift. Anyway, if we admit your axiom as granted, then we can also admit that the following version does not work (version of my initial post): >> >> pr :: Name -> ExpQ >> >> pr n = [| putStrLn $ (nameBase n) ++ " = " ++ show $(varE n) |] Thanks, TP _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe