I think the short answer is that the magic function is expected to work, since the quotation brackets really fix their local variables (in a sense). Essentially, local compile-time variables in square brackets are replaced by their literal values and become run-time constants. This is achieved by secretly invoking the elevator function, so that [| .. var .. |] becomes [| $ (lift var) |].
Perhaps you are confusing this behavior with the fact that they fix local variables uniquely, so that repeated calls to the same quote will not interfere with other variable names. This is achieved by calling newName behind the scenes, which provides unique variable names.
If this helps, I personally think of quotation brackets as “splicing generators” - small pieces of Haskell code that will be converted to AST at compile time and therefore become splines ready to be included anywhere. As indicated in Bulat's manuals ( links from ), they act as a form of macro preprocessor, as they are a mixture of Haskell functions that generate code and a simple automatic conversion of haskell code to TH AST.
Edit: It seems that I beat me to the answer - I leave my answer if it gives additional value.
source share