imp: A GHC plugin for automatically importing modules.

[ library, mit, plugin ] [ Propose Tags ]

Imp is a GHC plugin for automatically importing modules.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
pedanticDisabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.2024.3.18, 0.2024.3.20, 0.2024.3.20.1, 0.2024.3.21, 1.0.0.0, 1.0.0.1, 1.0.1.0, 1.0.2.0
Change log CHANGELOG.md
Dependencies base (>=4.17.0.0 && <4.18 || >=4.18.0.0 && <4.19 || >=4.19.0.0 && <4.20), containers (>=0.6.7 && <0.7), exceptions (>=0.10.5 && <0.11), ghc (>=9.4.1 && <9.5 || >=9.6.1 && <9.7 || >=9.8.1 && <9.9) [details]
License MIT
Author
Maintainer Taylor Fausak
Category Plugin
Source repo head: git clone https://github.com/tfausak/imp
Uploaded by fozworth at 2024-03-22T14:41:10Z
Distributions NixOS:1.0.1.0, Stackage:1.0.2.0
Downloads 140 total (80 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-03-22 [all 1 reports]

Readme for imp-1.0.0.0

[back to package description]

Imp

Workflow Hackage Stackage

Imp is a GHC plugin for automatically importing modules. This behavior is similar to the -fimplicit-import-qualified flag for GHCi. In short, Imp allows you to use fully-qualified identifiers without explicitly importing any modules.

Basic Usage

To use Imp, add it to your package's build-depends, like this:

library
  build-depends: imp

Then you can enable it with the -fplugin=Imp flag for GHC, like this:

{-# OPTIONS_GHC -fplugin=Imp #-}
main = System.IO.print ()

For the above module, Imp will automatically import System.IO for you. It's as though you wrote this instead:

import qualified System.IO
main = System.IO.print ()

Enabling Everywhere

More often than not, you'll probably want to enable Imp for an entire component rather than for a single module. To do that, add it to your package's ghc-options, like this:

library
  ghc-options: -fplugin=Imp

Then you don't need to use the OPTIONS_GHC pragma to enable Imp.

Aliasing Modules

Sometimes you may want to refer to modules by an alias. For example you may prefer using System.IO as simply IO. Imp supports this with the --alias=SOURCE:TARGET option. Here's an example:

{-# OPTIONS_GHC
  -fplugin=Imp
  -fplugin-opt=Imp:--alias=System.IO:IO #-}
main = IO.print ()

That is the same as writing this:

import qualified System.IO as IO
main = IO.print ()

Later aliases will override earlier ones.

Notes

Imp operates purely syntactically. It doesn't know anything about the identifiers that you use. So if you refer to something that doesn't exist, like System.IO.undefined, you'll get an error from GHC.

Imp will never insert an import for a module that you've explicitly imported. It will only insert an import when the module is not in scope already.