@hackage imp1.0.0.0

A GHC plugin for automatically importing modules.

  • Installation

  • Dependencies (4)

  • Dependents (0)

  • Package Flags

      pedantic
       (off by default)

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.