[GHC] #10047: inconsistency in name binding between splice and quasiquotation
GHC
ghc-devs at haskell.org
Fri Jan 30 18:28:34 UTC 2015
#10047: inconsistency in name binding between splice and quasiquotation
-------------------------------------+-------------------------------------
Reporter: rwbarton | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Template | Version: 7.8.4
Haskell | Operating System: Unknown/Multiple
Keywords: | Type of failure: None/Unknown
Architecture: | Blocked By:
Unknown/Multiple | Related Tickets:
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
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 at 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.)
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10047>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list