The idea is simple, mExport parses all the imports of all modules in an Haskell project. Using the import details it can curate a list of functions, types, etc. required from a particular module.
To get the best results you can do the following:
You can add the below ghc-options to your project to dump the minimal imports which can be used by mExport.
In stack.yaml
ghc-options:
- -ddump-minimal-imports
In .cabal
ghc-options: -ddump-minimal-imports
GHC will dump the minimal imports into a directory which is used by mExport.
mExport automatically detects these dump directories by itself. Raise an issue if it's incorrect.
Note: This detection works by using stack/cabal tool. Hence it's required to be available in PATH
Caution: mExport isn't tested with custom dump dir given using
-dump-dir
ghc option
stack purge
stack build
-- or --
cabal v2-clean
cabal v2-build
Commands:
git clone https://github.com/mycodedstuff/mExport
cd mExport
stack install #or cabal v2-install
mexport --help
Make sure you have ~/.local/bin
(if installed via stack) or ~/.cabal/bin
(if installed via cabal) in your PATH
Note: If you don't have ghc 8.10.7 installed it will install it which may take more time.
Simply run mexport
in your project directory
For cli options run mexport --help
CLI Options:
mExport 0.0.1 - minimize export list of haskell modules
Usage: mexport [--version | [--path DIR] [--analyze] [--extensions GHCEXT]
[--dump-dir DIR] [--indent NUM] [--collapse NUM]]
Available options:
--version Print the version
--path DIR Path of Haskell project (default: ".")
--analyze Analyze the Haskell project, helps in verifying if
project can be parsed
--extensions GHCEXT Comma separated GHC Language extensions
--indent NUM Indentation for the exports
--collapse NUM Exports everything of a type if NUM or more
percentage is exported
-h,--help Show this help text
You can also provide some options using a yaml configuration file
Create a .mexport.yaml
inside the project directory, mExport
will detect the file itself
indent: 2
collapse: 80
extensions:
- BangPatterns
- TypeApplications
- This could be due to ambiguity errors where an unqualified import of module may have same things as the module exporting it.
- The import statement might be explicitly importing something which isn't used in the module
- A module might be re-exporting an imported module, currently mexport doesn't support these.
- Something else? Raise an issue.
- These would mostly be due to unused code in your code base
- Something else? Raise an issue to let me know.
- MExport doesn't handle reexported modules
- MExport overwrites exports of modules hence any comments in between them gets overwritten