Missing interface-file declaration when splicing lifted quote
I'm testing out ways to "transport" Template Haskell splices. E.g. consider this module:
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
module Test (y) where
import Language.Haskell.TH
x :: Int
x = 1
y :: Q Exp
y = [|x|]
Another module can import this module and even access the x
variable which is not exported. I assume there are some internal rules that add x
to the interface file because it is used in the quasi quote.
But if we use a quasi quote in a splice then it seems like this does not happen. E.g. in this version:
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
module Test (y) where
import Lift -- module that defines Lift instances for all TH types.
import Language.Haskell.TH.Syntax
x :: Int
x = 1
y :: Q Exp
y = pure $(lift =<< [|x|])
Now importing and using the value y
will result in an error, e.g. like this:
{-# LANGUAGE TemplateHaskell #-}
import Test
main :: IO ()
main = print $(y)
It produces this error:
Main.hs:5:16: error:
• Can't find interface-file declaration for variable Test.x
Probable cause: bug in .hi-boot file, or inconsistent .hi file
Use -ddump-if-trace to get an idea of which file caused the error
• In the first argument of ‘print’, namely ‘(Test.x)’
In the expression: print (Test.x)
In an equation for ‘main’: main = print (Test.x)
|
5 | main = print $(y)
| ^
I understand that this is probably not what Template Haskell was designed for, but I would love it if GHC would add x
to the interface file when it is quoted in a splice like this.
Here is the full code in the `Lift` module
{-# LANGUAGE DeriveLift, StandaloneDeriving #-}
module Lift where
import Language.Haskell.TH.Syntax
deriving instance Lift Name
deriving instance Lift NameFlavour
deriving instance Lift PkgName
deriving instance Lift NameSpace
deriving instance Lift ModName
deriving instance Lift OccName
deriving instance Lift Clause
deriving instance Lift Pat
deriving instance Lift Exp
deriving instance Lift Range
deriving instance Lift Match
deriving instance Lift Body
deriving instance Lift Guard
deriving instance Lift Stmt
deriving instance Lift Dec
deriving instance Lift PatSynDir
deriving instance Lift PatSynArgs
deriving instance Lift Role
deriving instance Lift TypeFamilyHead
deriving instance Lift InjectivityAnn
deriving instance Lift FamilyResultSig
deriving instance Lift TySynEqn
deriving instance Lift Pragma
deriving instance Lift AnnTarget
deriving instance Lift RuleBndr
deriving instance Lift Phases
deriving instance Lift RuleMatch
deriving instance Lift Inline
deriving instance Lift Fixity
deriving instance Lift FixityDirection
deriving instance Lift Foreign
deriving instance Lift Safety
deriving instance Lift Callconv
deriving instance Lift Overlap
deriving instance Lift FunDep
deriving instance Lift DerivClause
deriving instance Lift DerivStrategy
deriving instance Lift Con
deriving instance Lift Bang
deriving instance Lift SourceUnpackedness
deriving instance Lift SourceStrictness
deriving instance Lift Lit
instance Lift Bytes where
liftTyped = error "TODO define Lift for Bytes"
deriving instance Lift Type
deriving instance Lift TyVarBndr
deriving instance Lift TyLit
Environment
- GHC version used: 8.10.4
Optional:
- Operating System: Debian 10
- System Architecture: x86_64