使用“派生”时模板Haskell错误

时间:2013-04-03 01:49:26

标签: haskell template-haskell

与我得到的结果有点混淆。使用以下内容:

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?

1 个答案:

答案 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]]