[GHC] #10478: Shorter import syntax

GHC ghc-devs at haskell.org
Wed Jun 3 17:41:07 UTC 2015


#10478: Shorter import syntax
-------------------------------------+-------------------------------------
        Reporter:  acowley           |                   Owner:
            Type:  feature request   |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Compiler          |                 Version:  7.10.1
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  None/Unknown      |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------

Comment (by goldfire):

 I'm in favor of abbreviating the syntax in this common scenario, but I
 don't like your choice of syntax, I'm afraid. It would give

 {{{
 import Data.Map (Map) as M    -- (1)
 }}}

 a very different meaning from

 {{{
 import Data.Map as M (Map)    -- (2)
 }}}

 (1) imports all of `Data.Map`, qualified with the alias `M`, and imports
 the name `Map` unqualified. (2) imports only the name `Map` (unqualified)
 while also aliasing `Data.Map`.
 Having these two coexist seems like we're asking users to be confused.

 What about

 {{{
 import Data.Map (Map)
   qualified as M *
 }}}

 ?

 The general schema, which replaces the current syntax. This schema does
 not permit some current syntax, but it would be easy to extend it to be
 backward-compatible. I've chosen not to for this presentation to avoid
 clutter.

 {{{
 import_statement  ::= 'import' module_name maybe_name_list
 import_specifiers
 module_name       ::= ...
 maybe_name_list   ::= name_list | <empty>
 name_list         ::= '(' names ')' | '*'
 import_specifiers ::= <empty> | import_specifier import_specifiers
 import_specifier  ::= 'hiding' name_list | qualified_spec name_list
 qualified_spec    ::= 'qualified' | 'qualified' 'as' name
 }}}

 The top-level `maybe_name_list` would list all unqualified imports. If it
 is omitted, and there are no `qualified_spec`s, then all names would be
 imported unqualified. If it is omitted and there are one or more
 `qualified_spec`s, then no names would be imported unqualified.

 Each `import_specifier` either adds qualified names (perhaps under a
 module synonym) or removes names. Removing names with `hiding` removes
 those names from the `qualified_spec` (or top-level `maybe_name_list`)
 immediately preceding the `hiding`.

 The special `name_list` `*` (note that it is ''not'' in parentheses, to
 avoid ambiguity) means "all names".

 This schema allows one import statement to import a mix of qualified and
 unqualified names, and even allows using different module synonyms for
 different sets of qualified names. The legacy `import` syntax could
 desugar to this form, which seems strictly more expressive. For example:

 {{{
 import qualified Foo       -->  import Foo qualified *
 import qualified Bar as B  -->  import Bar qualified as B *
 import Baz hiding (wurble) -->  import Baz hiding (wurble)
 }}}

 Thoughts?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10478#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list