The closest I can see is using reifyModule
and thisModule
, but that doesn't work.
{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
main = putStrLn $(LitE . StringL . show <$> thisModule)
(unsurprisingly) gives back Module (PkgName "main") (ModName "Main")
regardless of the file name.
You can get it using location
.
{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
main = putStrLn $(LitE . StringL . loc_filename <$> location)