How to get the current module name in Haskell?

I thought this was a nice question, so I figured out the answer using Template Haskell.

I thought this was a nice question, so I figured out the answer using Template Haskell: {-# LANGUAGE TemplateHaskell #-} module A.B. C where import Language.Haskell. TH import Language.Haskell.TH. Syntax e :: String e = $(fmap loc_module qLocation >>= \mod -> return (LitE (StringL mod) )) main = print e.

1 Note that I think this bit of Template Haskell only works at compile time, using runQ at runtime will not work. – Chris Kuklewicz Mar 30 at 0:44 4 How often does Template Haskell work at runtime? – Antoine Latter Mar 30 at 2:04.

There's a rather roundabout way to get the current module name using Typeable. Module My.Module. Blah where import Data.

Typeable data T = T deriving Typeable test = init $ init $ show $ typeOf T.

Great answers. We ended up doing it this way as it seemed a little cleaner. ModuleOf 'someTopLevelThingInModule moduleOf :: Language.Haskell.TH.Syntax.Name -> String moduleOf = dropLastToken .

Show dropLastToken :: String -> String dropLastToken = reverse . Tail . DropWhile (/= '.

') . Reverse.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions