Skip to content

Commit 4c5d26f

Browse files
committed
Add note on import...as to tutorial
1 parent 6bb6ced commit 4c5d26f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/source/tutorial/modules.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,35 @@ The module ``A`` will export the name ``a``, as well as any public or
179179
abstract names in module ``C``, but will not re-export anything from
180180
module ``B``.
181181

182+
Renaming imports
183+
----------------
184+
185+
Sometimes it is convenient to be able to access the names in another module
186+
via a different namespace (typically, a shorter one). For this, you can
187+
use `import...as`. For example:
188+
189+
::
190+
191+
module A
192+
193+
import Data.List as L
194+
195+
This module ``A`` has access to the exported names from module ``Data.List``,
196+
but can also explicitly access them via the module name ``L``. ``import...as``
197+
can also be combined with ``import public`` to create a module which exports
198+
a larger API from other sub-modules:
199+
200+
::
201+
202+
module Books
203+
204+
import Books.Hardback as Books
205+
import Books.Comic as Books
206+
207+
Here, any module which imports ``Books`` will have access to the exported
208+
interfaces of ``Books.Hardback`` and ``Books.Comic`` both under the namespace
209+
``Books``.
210+
182211
Explicit Namespaces
183212
===================
184213

0 commit comments

Comments
 (0)