gpt4 book ai didi

haskell - 使用 "deriving"时模板 Haskell 错误

转载 作者:行者123 更新时间:2023-12-04 11:54:35 24 4
gpt4 key购买 nike

对我得到的结果有点困惑。使用以下内容:

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?

最佳答案

看起来这是一个 bug in GHC那是fixed在 7.6.1 版中:

$ ~/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]]

关于haskell - 使用 "deriving"时模板 Haskell 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15777527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com