The modulespection package

[Tags:bsd3, library]

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.

Properties

Versions 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.0.7, 0.1.1.0, 0.1.2.0, 0.1.2.1, 0.1.2.2
Dependencies base (>=4.6 && <666), exceptions (>=0.5 && <0.7), filepath (==1.3.*), ghc, ghc-paths (==0.1.*), template-haskell (>=2.7), temporary (==1.2.*), transformers (>=0.3 && <0.5) [details]
License BSD3
Author Jonathan Fischoff
Maintainer jonathangfischoff@gmail.com
Category Language
Home page https://github.com/jfischoff/modulespection
Source repository head: git clone git://github.com/jfischoff/modulespection
Uploaded Mon Feb 2 03:36:11 UTC 2015 by JonathanFischoff
Distributions NixOS:0.1.2.2
Downloads 2220 total (21 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2015-02-02 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees