GHC/QualifiedModuleExport

From HaskellWiki


Motivation[edit]

There are a number of libraries in the Haskell ecosystem which encourage qualified imports to avoid name clashes with other modules. For example:

   -- Import the ByteString and Text types un-qualified.
  import Data.ByteString (ByteString)
  import Data.Map.Strict (Map)
  import Data.Text (Text)

  -- Import ByteString and Text modules qualified to avoid name collisions.
  import qualified Data.ByteString.Char8 as BS
  import qualified Data.Map.Strict as Map
  import qualified Data.Text as T

In larger projects the above lines will need to be added to every file that uses ByteString, Map and Text.

The problem for the types can easily be fixed by creating a Prelude module which does the following:

  module MyPrelude
      ( Text
      , Map
      , ByteString
      ) where
  import Data.ByteString (ByteString)
  import Data.Map.Strict (Map)
  import Data.Text (Text)

and then importing MyPrelude to access the types. Unfortunately there is currently no way to add qualified module exports to MyPrelude and have those qualified names available to modules that import MyPrelude.

Background[edit]

The following is a list of previous documents and discussions about Haskell's module system:

The Proposal[edit]

This proposal extends the export mechanism so that the following is possible:

  module MyPrelude
      ( Text
      , Map
      , ByteString
      , qualified module BS
      , qualified module Map
      , qualified module T
      ) where
  import Data.ByteString (ByteString)
  import Data.Map.Strict (Map)
  import Data.Text (Text)

  import qualified Data.ByteString.Char8 as BS
  import qualified Data.Map.Strict as Map
  import qualified Data.Text as T

Files which originally had 6 lines of imports can now replace those 6 lines with a single import of MyPrelude.