Error when reifying type constructor
The following code works under ghc-7.6.3 and template-haskell-2.8.0.0:
{-# LANGUAGE TemplateHaskell #-}
data Huh = ThisDefinitely
| UsedToWork
constructorNames :: String
constructorNames = $(do
ty <- reify ''Huh
let strs = case ty of
(TyConI (DataD _ _ _ cons _)) -> map showCon cons
showCon (NormalC n _) = nameBase n
return . LitE . StringL $ concat strs)
main = putStrLn constructorNames
Printing the following at compile time:
[1 of 1] Compiling Main ( Main.hs, Main.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.4.0.1 ... linking ... done.
Loading package deepseq-1.3.0.1 ... linking ... done.
Loading package containers-0.5.0.0 ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Linking Main ...
and then successfully executing:
$ ./Main
ThisDefinitelyUsedToWork
However, using ghc 7.8.3/template-haskell-2.9.0.0 I get the following compile error:
[1 of 1] Compiling Main ( Main.hs, Main.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... 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 pretty-1.1.1.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
Main.hs:8:22:
‘Huh’ is not in the type environment at a reify
In the splice:
$(do { ty <- reify ''Huh;
let showCon (NormalC n _) = ...
....;
return . LitE . StringL $ concat strs })
Is this expected? I couldn't see anything in the GHC release notes to suggest this should no longer work.