TemplateHaskell - variables in top level splices and loading modules.
The following code fails when loading Main module:
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}
module TH where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Data.Typeable
usingType :: a -> Q [Dec]
usingType _ = do
let name = "The name!"
-- theF = "The name!"
return [FunD (mkName "theF") [Clause [] (NormalB $ LitE $ StringL name ) []]]
{-# LANGUAGE TemplateHaskell #-}
module Main where
import TH
data A = A Int
-- Runs with `usingType (undefined :: A)` instead
$(usingType (A 3) )
main = putStrLn $ theF
The error:
$ ghc --make Main.hs
[1 of 2] Compiling TH ( TH.hs, TH.o )
[2 of 2] Compiling Main ( Main.hs, Main.o )
attempting to use module ‘Main’ (Main.hs) which is not loaded
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |