Vladislav Zavialov pushed to branch wip/int-index/imp-exp-whole-namespace at Glasgow Haskell Compiler / GHC
Commits:
-
6aabe758
by Vladislav Zavialov at 2025-10-29T14:34:28+03:00
3 changed files:
- compiler/GHC/Hs/Basic.hs
- docs/users_guide/9.16.1-notes.rst
- docs/users_guide/exts/explicit_namespaces.rst
Changes:
| ... | ... | @@ -67,24 +67,26 @@ instance Binary FixityDirection where |
| 67 | 67 | --
|
| 68 | 68 | -- * import/export items
|
| 69 | 69 | -- * fixity signatures
|
| 70 | --- * WARNINIG and DEPRECATED pragmas
|
|
| 70 | +-- * @WARNINIG@ and @DEPRECATED@ pragmas
|
|
| 71 | 71 | --
|
| 72 | 72 | -- Examples:
|
| 73 | 73 | --
|
| 74 | --- module M (data ..) where
|
|
| 75 | --- -- ↑ DataNamespaceSpecifier
|
|
| 74 | +-- @
|
|
| 75 | +-- module M (data ..) where
|
|
| 76 | +-- -- ↑ DataNamespaceSpecifier
|
|
| 76 | 77 | --
|
| 77 | --- import Data.Proxy (type ..) as T
|
|
| 78 | --- -- ↑ TypeNamespaceSpecifier
|
|
| 78 | +-- import Data.Proxy as T (type ..)
|
|
| 79 | +-- -- ↑ TypeNamespaceSpecifier
|
|
| 79 | 80 | --
|
| 80 | --- {-# WARNING in "x-partial" data Head "don't use this pattern synonym" #-}
|
|
| 81 | --- -- ↑ DataNamespaceSpecifier
|
|
| 81 | +-- {-# WARNING in "x-partial" data Head "don't use this pattern synonym" #-}
|
|
| 82 | +-- -- ↑ DataNamespaceSpecifier
|
|
| 82 | 83 | --
|
| 83 | --- {-# DEPRECATED type D "This type was deprecated" #-}
|
|
| 84 | --- -- ↑ TypeNamespaceSpecifier
|
|
| 84 | +-- {-# DEPRECATED type D "This type was deprecated" #-}
|
|
| 85 | +-- -- ↑ TypeNamespaceSpecifier
|
|
| 85 | 86 | --
|
| 86 | --- infixr 6 data $
|
|
| 87 | --- -- ↑ DataNamespaceSpecifier
|
|
| 87 | +-- infixr 6 data $
|
|
| 88 | +-- -- ↑ DataNamespaceSpecifier
|
|
| 89 | +-- @
|
|
| 88 | 90 | data NamespaceSpecifier
|
| 89 | 91 | = NoNamespaceSpecifier
|
| 90 | 92 | | TypeNamespaceSpecifier (EpToken "type")
|
| ... | ... | @@ -112,4 +114,4 @@ coveredByNamespaceSpecifier DataNamespaceSpecifier{} = isValNameSpace |
| 112 | 114 | instance Outputable NamespaceSpecifier where
|
| 113 | 115 | ppr NoNamespaceSpecifier = empty
|
| 114 | 116 | ppr TypeNamespaceSpecifier{} = text "type"
|
| 115 | - ppr DataNamespaceSpecifier{} = text "data" |
|
| \ No newline at end of file | ||
| 117 | + ppr DataNamespaceSpecifier{} = text "data" |
| ... | ... | @@ -16,6 +16,9 @@ Language |
| 16 | 16 | result, you may need to enable :extension:`DataKinds` in code that did not
|
| 17 | 17 | previously require it.
|
| 18 | 18 | |
| 19 | +- The extension :extension:`ExplicitNamespaces` now allows namespace-specified
|
|
| 20 | + wildcards ``type ..`` and ``data ..`` in import and export lists.
|
|
| 21 | + |
|
| 19 | 22 | Compiler
|
| 20 | 23 | ~~~~~~~~
|
| 21 | 24 |
| ... | ... | @@ -118,6 +118,36 @@ The ``pattern`` keyword does the same, with only a few differences: |
| 118 | 118 | The ``data`` keyword is preferred over ``pattern`` in import/export lists unless
|
| 119 | 119 | there is a need to support older GHC versions.
|
| 120 | 120 | |
| 121 | +Wildcards in import/export lists
|
|
| 122 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 123 | + |
|
| 124 | +**Since:** GHC 9.16
|
|
| 125 | + |
|
| 126 | +Namespace-specified wildcards ``type ..`` and ``data ..`` may be used to import
|
|
| 127 | +all names in the corresponding namespace from a module: ::
|
|
| 128 | + |
|
| 129 | + import M (type ..) -- imports all type and class constructors from M
|
|
| 130 | + import M (data ..) -- imports all data constructors and terms from M
|
|
| 131 | + |
|
| 132 | +The primary intended use of this feature is in combination with module aliases,
|
|
| 133 | +allowing namespace disambiguation: ::
|
|
| 134 | + |
|
| 135 | + import Data.Proxy as T (type ..) -- T.Proxy is unambiguously the type constructor
|
|
| 136 | + import Data.Proxy as D (data ..) -- D.Proxy is unambiguously the data constructor
|
|
| 137 | + |
|
| 138 | +Using both wildcards ``import M (type .., data ..)`` is legal but redundant, as
|
|
| 139 | +it is equivalent to ``import M`` with no import list.
|
|
| 140 | + |
|
| 141 | +Similarly, one may use wildcards in the export list of a module: ::
|
|
| 142 | + |
|
| 143 | + module M (type .., f) where
|
|
| 144 | + -- exports all type and class constructors defined in M,
|
|
| 145 | + -- plus the function 'f'
|
|
| 146 | + |
|
| 147 | +Using both wildcards ``module M (type .., data ..)`` is legal but redundant, as
|
|
| 148 | +it is equivalent to a whole module reexport ``module M (module M)``.
|
|
| 149 | + |
|
| 150 | + |
|
| 121 | 151 | Explicit namespaces in fixity declarations and warning/deprecation pragmas
|
| 122 | 152 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 123 | 153 |