-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Template Haskell for introspecting a module's declarations -- -- Collect all of the declarations in a module using Template Haskell -- (via the GHC API). -- -- One can either get all the names, or just the declarations (only type -- declarations are supported right now). -- -- Here is a quick example: -- --
-- import Language.Haskell.TH.Module.Magic (names) -- -- data Test = Test Int -- newtype OtherTest = OtherTest Test -- -- someFunction :: String -> String -- someFunction = id -- -- -- 'names' is Template Haskell function that will collect all of the -- -- toplevel declaration names of the current file. -- names >>= runIO . print >> return [] ---- -- Which will spew the following when compiling: -- --
-- [Test,OtherTest,someFunction] ---- -- There is also declarations which can be used, for example, to -- make sure that all types have ToJSON/FromJSON -- instances. -- --
-- import Data.Aeson.TH (deriveJSON, defaultOptions) -- import MonadUtils (concatMapM) -- import Language.Haskell.TH.Module.Magic (declarations) -- -- data Test = Test Int -- newtype OtherTest = OtherTest Test -- -- concatMapM (deriveJSON defaultOptions) =<< declarations ---- -- Which will make JSON instances for Test, OtherTest and any other types -- added to the file. -- -- You can also do the same thing for an existing module. -- --
-- import Data.Aeson.TH (deriveJSON, defaultOptions) -- import MonadUtils (concatMapM) -- import Language.Haskell.TH.Module.Magic (moduleDeclarations) -- import Data.Monoid -- -- concatMapM (deriveJSON defaultOptions) =<< moduleDeclarations "Data.Monoid" ---- -- Which will build instances for all the types in Data.Monoid. @package modulespection @version 0.1.2.1 module Language.Haskell.TH.Module.Magic -- | Get all the top level declarations of the current file. All names are -- returned whether they are exported or not. names :: Q [Name] -- | Get all the top level names of a given module. If a file path is used, -- all names, exported and internal are returned. If a module name is -- used, only the exported names are returned. moduleNames :: String -> Q [Name] -- | Get all the type declarations of the current file. Function and -- pattern declarations are ignored ... for now. declarations :: Q [Dec] -- | Get all the top level names of a given module. If a file path is used, -- all names, exported and internal are returned. If a module name is -- used, only the exported names are returned. Function and pattern -- declarations are ignored ... for now. moduleDeclarations :: String -> Q [Dec] instance GetNameMaybe RdrName instance GetNameMaybe a => GetNameMaybe (GenLocated SrcSpan a) instance GetNameMaybe (HsBindLR RdrName RdrName) instance GetNameMaybe (TyClDecl RdrName) instance GetNameMaybe (HsDecl RdrName) instance MonadCatch Ghc instance MonadThrow Ghc instance MonadIO Ghc