wiki:TagExportsWithNamespace

Version 2 (modified by malcolm.wallace@…, 9 years ago) (diff)

alternative proposal

Tag exported entities with their namespace

In export and import lists, it is easy to distinguish functions from types/constructors/classes, because they are lexically different - vars begin with lower-case, the rest with upper-case. However, it is much more difficult to distinguish types, from constructors, from classes.

Proposal

Each type or class constructor in an import or export list can be (optionally) annotated with its namespace, e.g.

import Foo (class Foo (Foo,Bar), data Baz())

Grammar changes

The production for exported entities changes from

    export  -> qvar
            |  qtycon [ (..) | ( cname_1, ... , cname_n ) ]	(n>=0)
            |  qtycls [ (..) | ( var_1, ... , var_n ) ]		(n>=0)
            |  module modid

to

    export  -> qvar
            |  [type]    qtycon
            |  [newtype] qtycon [ (..) | ( cname_1, ... , cname_n )	(n>=0)
            |  [data]    qtycon [ (..) | ( cname_1, ... , cname_n )	(n>=0)
            |  [class]   qtycls [ (..) | ( var_1, ... , var_n )		(n>=0)
            |  module modid

and that for imported entities from

    import  -> var
            | tycon [ (..) | ( cname_1, ... , cname_n ) ]	(n>=0)
            | tycls [ (..) | ( var_1, ... , var_n ) ]		(n>=0)

to

    import  -> var
            | [type]    tycon
            | [newtype] tycon [ (..) | ( cname_1, ... , cname_n ) ]	(n>=0)
            | [data]    tycon [ (..) | ( cname_1, ... , cname_n ) ]	(n>=0)
            | [class]   tycls [ (..) | ( var_1, ... , var_n ) ]		(n>=0)

Variations

It would be better not to need to distinguish between type, newtype, and data. These names all live in the same namespace. And for implementation-abstract reasons, it would be useful not to need to reveal exactly how a type constructor was defined. So an alternative proposal is to use no keyword for type constructors, but the 'class' keyword for classes. This distinguishes the two capitalised namespaces exactly, and minimally. With this scheme, we should probably remove the optionality of the class keyword.

    export  ->        qvar
            |         qtycon [ (..) | ( cname_1, ... , cname_n )	(n>=0)
            |  class  qtycls [ (..) | ( var_1, ... , var_n )		(n>=0)
            |  module modid

    import  ->       var
            |        tycon [ (..) | ( cname_1, ... , cname_n ) ]	(n>=0)
            |  class tycls [ (..) | ( var_1, ... , var_n ) ]		(n>=0)