Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template Haskell error when using "deriving"

A little confused with the results I'm getting. Using the following:

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

I get this successful result:

Prelude Language.Haskell.TH> runQ [d| data X = X |]
[DataD [] X_0 [] [NormalC X_1 []] []]

But I get this error:

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) |]

I can't derive Show when using Template Haskell?

like image 418
me2 Avatar asked Apr 03 '13 01:04

me2


1 Answers

Looks like this was a bug in GHC that was fixed in version 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]]
like image 149
Mikhail Glushenkov Avatar answered Nov 14 '22 11:11

Mikhail Glushenkov