inconsistency in name binding between splice and quasiquotation
Let me preface this by saying that this may not be a bug. If not then it would be nice if the documentation for Template Haskell could clarify what's going on here.
My understanding of quasiquotation is that a quasiquote [n|foo|]
is equivalent to a splice $(quoteExp n "foo")
. However, that is not the case in all contexts.
module Q where
import Language.Haskell.TH
import Language.Haskell.TH.Quote
n = QuasiQuoter { quoteExp = dyn }
rwbarton@morphism:/tmp$ ghci -XTemplateHaskell -XQuasiQuotes Q
GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Q ( Q.hs, interpreted )
Q.hs:6:5: Warning:
Fields of ‘QuasiQuoter’ not initialised: quotePat, quoteType,
quoteDec
In the expression: QuasiQuoter {quoteExp = dyn}
In an equation for ‘n’: n = QuasiQuoter {quoteExp = dyn}
Ok, modules loaded: Q.
*Q> :t [| $(dyn "foo") |]
[| $(dyn "foo") |] :: ExpQ
*Q> :t [| [n|foo|] |]
Loading package pretty-1.1.1.1 ... linking ... done.
Loading package array-0.5.0.0 ... linking ... done.
Loading package deepseq-1.3.0.2 ... linking ... done.
Loading package containers-0.5.5.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
<interactive>:1:7:
Not in scope: ‘foo’
In the Template Haskell quotation [| [n|foo|] |]
Why do these behave differently?
(Lastly, the link to the paper "Why It's Nice to be Quoted: Quasiquoting for Haskell" in the User's Guide at https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/template-haskell.html#th-quasiquotation is broken. Does this paper have a permanent home? In any case, I only skimmed it but it didn't seem to answer my question.)
Trac metadata
Trac field | Value |
---|---|
Version | 7.8.4 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Template Haskell |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |