3

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.

Alex R
  • 2,201
  • 1
  • 19
  • 32

1 Answers1

4

You can get it using location.

{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH
import Language.Haskell.TH.Syntax

main = putStrLn $(LitE . StringL . loc_filename <$> location)
snak
  • 6,483
  • 3
  • 23
  • 33