Elm Exactly

Rule 48sm-imports-import

ImportsB,π⊢imports⇒π′\jdg{B, \pi}{\imports}{\pi'}
(MEofB)(modid)=Iπ1=π⊎modid(∅, modid′′.Dom I)⟨ ⁣⟨modid,I⊢explist⇒(N,N′)⟩ ⁣⟩π2=π1 ⟨ ⁣⟨⊎modid(N,N′)⟩ ⁣⟩B,π2⊢imports⇒π′B,π⊢import modid ⟨as modid′⟩ ⟨ ⁣⟨exposing explist⟩ ⁣⟩ imports⇒π′\frac{\begin{array}{c}(\ME \of B)(\modid) = I \premsep \pi_1 = \pi \smmerge_{\modid} (\emptyset,\ \modid''.\Dom I) \\ \optt{\jdg{\modid, I}{\explist}{(N, N')}} \premsep \pi_2 = \pi_1\ \optt{{}\smmerge_{\modid} (N, N')} \\ \jdg{B, \pi_2}{\imports}{\pi'}\end{array}}{\begin{array}{c}\jdg{B, \pi}{\kw{import}\ \modid\ \opt{\kw{as}\ \modid'}\ \optt{\kw{exposing}\ \explist}\ \imports}{\pi'}\end{array}}
(48)
Read it in its chapter·Permanent address: /standard/rules/sm-imports-import

Comments

Every identifier that the module exposes becomes available under the qualifier modid′′\modid'', and the identifiers listed by the exposing list become available unqualified. With as, the qualifier is modid′\modid' instead of modid\modid: after import Dict as D the identifier Dict.empty is not available through this import. Several imports may share a qualifier; their identifiers are joined under it, and an identifier exposed under one qualifier by two modules is ambiguous. Since the imports are read from left to right, a later import replaces what an earlier one provides for the identifiers in its NN. A module that is not in MEofB\ME \of B cannot be imported.

Referred to from

TeX source
\defnrule[r:sm-imports-import]
  {(\ME \of B)(\modid) = I \premsep \pi_1 = \pi \smmerge_{\modid} (\emptyset,\ \modid''.\Dom I) \\ \optt{\jdg{\modid, I}{\explist}{(N, N')}} \premsep \pi_2 = \pi_1\ \optt{{}\smmerge_{\modid} (N, N')} \\ \jdg{B, \pi_2}{\imports}{\pi'}}
  {\jdg{B, \pi}{\kw{import}\ \modid\ \opt{\kw{as}\ \modid'}\ \optt{\kw{exposing}\ \explist}\ \imports}{\pi'}}

Tests (4)

  • elm / CompilerIssue2119MutualRecursionUnannotatedTest
    An exposed, unannotated, mutually recursive function used from another module compiles and runs.
  • elm / CovForeignTypesTest
    Checks the use of two values from another module of the same project: `secretValue`, whose annotation names a type alias that its module does not expose, and a field of `config`, read through the module name as `CovForeignTypesHelper.config.x`. Their sum, 42, is logged.
  • elm / ImportResolutionQualifiedImportedFunctionTest
    A call written with the module qualifier, `Basics.negate`, resolves to the imported function even though the module is also imported with `exposing (..)`.
  • elm / ImportTypeByNameLaterReplacesTest
    When two imports expose a type of the same name by name, the later import's type is the one the name denotes: the name is not ambiguous.

Discussions

Discuss this rule·Search the discussions on GitHub

Discussions are on GitHub; one about this rule has [r:sm-imports-import] in its title.

A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.