auto-export: Automatically add things to module export list

[ bsd3, development, library ] [ Propose Tags ] [ Report a vulnerability ]

Automatically add things to module export list using a GHC plugin


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies base (<5), bytestring (<0.13), containers, ghc (>=9.6 && <9.13), ghc-exactprint, ghc-paths, mtl (>=2.3) [details]
Tested with ghc ==9.12.1, ghc ==9.10.1, ghc ==9.8.1, ghc ==9.6.1
License BSD-3-Clause
Copyright 2025 Aaron Allen
Author Aaron Allen
Maintainer aaronallen8455@gmail.com
Category Development
Source repo head: git clone https://github.com/aaronallen8455/auto-export
Uploaded by aaronallen8455 at 2025-11-08T22:20:26Z
Distributions
Downloads 2 total (2 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
All reported builds failed as of 2025-11-08 [all 1 reports]

Readme for auto-export-0.1.0.0

[back to package description]

auto-export 📤

This is a GHC plugin that edits the file being compiled by adding a target top-level definition to the explicit export list of the module.

Usage

This plugin is intended to be used with GHCi or adjacent utilities such as ghcid and ghciwatch as a developement tool, not as a package dependency. Here is an example command for starting a REPL for a stack project with the auto-export plugin enabled (you may need to add auto-export to your extra-deps first):

stack repl my-project --package auto-export --ghci-options='-fplugin AutoExport'

likewise for a cabal project (you may need to run cabal update first):

cabal repl my-project --build-depends auto-export --repl-options='-fplugin AutoExport'

With the plugin enabled, mark the expression to be exported by placing !EXPORT on a line above it then compile the module. If the module has an explicit export list, the definition will be automatically added to it. Compilation is aborted after the code is updated.

For example, given this program:

module M () where

data Colors = Red | Green | Blue
  deriving (Enum, Bounded)

allColors :: [Colors]
allColors = [minBound .. maxBound]

Insert the export targets:

module M () where

!EXPORT
data Colors = Red | Green | Blue
  deriving (Enum, Bounded)

!EXPORT
allColors :: [Colors]
allColors = [minBound .. maxBound]

Compiling the module will result in the source code being updated to:

module M (Colors(..), allColors) where

data Colors = Red | Green | Blue
  deriving (Enum, Bounded)

allColors :: [Colors]
allColors = [minBound .. maxBound]

Data declarations and type classes are always exported in full using (..).

The plugin only supports certain GHC versions with the intent of supporting the four latest release series, i.e. 9.6.* thru 9.12.*. The cabal file indicates the currently supported versions.