Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 461
    • Merge requests 461
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #9813
Closed
Open
Created Nov 19, 2014 by owst@trac-owst

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.

Edited Mar 10, 2019 by owst
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking