Difference between revisions of "GHC/QualifiedModuleExport"

From HaskellWiki
< GHC
Jump to navigation Jump to search
(Created page with "Qualified Module Exports == Motivation == There are a number of libraries in the Haskell ecosystem which encourage qualified imports to avoid name clashes w...")
 
m ("thab" isn't a word)
 
(One intermediate revision by one other user not shown)
Line 34: Line 34:
 
</haskell>
 
</haskell>
   
and then importing MyPrelude to access the types. Unfortunately there is currently no way to add qualified module exports to <hask>MyPrelude</hask> and thab those qualified names available to modules that import <hask>MyPrelude</hask>.
+
and then importing MyPrelude to access the types. Unfortunately there is currently no way to add qualified module exports to <hask>MyPrelude</hask> and have those qualified names available to modules that import <hask>MyPrelude</hask>.
   
 
== Background ==
 
== Background ==
Line 40: Line 40:
   
 
* Iavor S. Diatchki et al's formal specification of the Haskell 98 module system: http://purely-functional.net/yav/publications/modules98.pdf
 
* Iavor S. Diatchki et al's formal specification of the Haskell 98 module system: http://purely-functional.net/yav/publications/modules98.pdf
* Module system in the Haskell 98 report: http://www.haskell.org/onlinereport/modules.html
+
* Module system in the Haskell 98 report: http://www.haskell.org/onlinereport/modules.html (code at: https://github.com/yav/module-98 )
 
* Module system in the Haskell 2010 report: http://www.haskell.org/onlinereport/haskell2010/haskellch5.html
 
* Module system in the Haskell 2010 report: http://www.haskell.org/onlinereport/haskell2010/haskellch5.html
 
* A thread from the haskell-cafe mailing list: http://www.haskell.org/pipermail/haskell-cafe/2005-March/thread.html
 
* A thread from the haskell-cafe mailing list: http://www.haskell.org/pipermail/haskell-cafe/2005-March/thread.html

Latest revision as of 22:21, 24 February 2016


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

Background

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

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.