Personal tools

GHC/QualifiedModuleExport

From HaskellWiki

< GHC
Revision as of 15:54, 29 September 2013 by Erikd (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


1 Motivation

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 thab those qualified names available to modules that import
MyPrelude
.

2 Background

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

3 The Proposal

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
.