与我得到的结果有点混淆。使用以下内容:
GHCi, version 7.4.2: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :m + Language.Haskell.TH
我得到了这个成功的结果:
Prelude Language.Haskell.TH> runQ [d| data X = X |]
[DataD [] X_0 [] [NormalC X_1 []] []]
但是我收到了这个错误:
Prelude Language.Haskell.TH> runQ [d| data X = X deriving Show |]
<interactive>:4:30:
The exact Name `X' is not in scope
Probable cause: you used a unique name (NameU) in Template Haskell but did not bind it
In the Template Haskell quotation [d| data X = X deriving (Show) |]
In the first argument of `runQ', namely
`[d| data X = X deriving (Show) |]'
In the expression: runQ [d| data X = X deriving (Show) |]
使用Template Haskell时无法导出Show?
答案 0 :(得分:7)
在7.6.1版本中看起来这是bug in GHC:
$ ~/bin/ghc-7.6.1/bin/ghci
GHCi, version 7.6.1: http://www.haskell.org/ghc/ :? for help
[...]
Prelude> :set -XTemplateHaskell
Prelude> import Language.Haskell.TH
Prelude Language.Haskell.TH> runQ [d| data X = X deriving (Show) |]
[...]
[DataD [] X_0 [] [NormalC X_1 []] [GHC.Show.Show]]