Elm Exactly
A Standard Definition of Elm?Draft version 0.4 / Chapter 7

7Dynamic Semantics for Modules

The dynamic semantics of Modules defines the dynamic interfaces that modules evaluate to, and the environments that imports and top-level declarations produce. Its sentences infer that a module evaluates to an interface in a basis, that a sequence of imports evaluates to an environment, that an exposing list cuts an interface down to the part it exposes, and that a top-level declaration evaluates to an interface in an environment. Modules are flat: a module makes its top-level values and constructors available by name, and there are no signatures or functors. Every module evaluated here is assumed to have elaborated in the static semantics of Chapter 5. The order in which the modules of a program are evaluated, and the meaning of main, are given in Chapter 9.

7.1Reduced Syntax

Types play no part in evaluation, except that a port must know what it sends or receives. For the dynamic semantics the syntax of Modules is reduced as follows, in addition to the reduction of the Core (Section 6.1):

  • The type annotations of top-level values are omitted, as in the Core. Since a module has no pattern bindings at the top level (Section 3.7), every top-level value declaration has the form

    var1 = exp1 and ⋯ and varn = expn(n≥1). \var_1\ \kw{=}\ \expm_1\ \kw{and}\ \cdots\ \kw{and}\ \var_n\ \kw{=}\ \expm_n\qquad(n\geq 1).
  • The type-variable sequence is omitted from every custom-type binding and every type-alias binding; the class TyVarSeq is omitted.

  • Each constructor binding con ty1⋯tyn\con\ \ty_1\cdots\ty_n is replaced by con\con, whose arity arity(con)\arity(\con) is nn (Section 6.3). Thus a constructor binding has the form con ⟨| conbind⟩\con\ \opt{\kw{|}\ \conbind}.

  • A type-alias binding tycon = ty\tycon\ \kw{=}\ \ty is replaced by tycon = {lab1, ⋯, labn}\tycon\ \kw{=}\ \kw{\kwlb}\lab_1\kw{,}\ \cdots\kw{,}\ \lab_n\kw{\kwrb} (n≥0)(n\geq 0) if it is a record alias (Section 3.7) whose record type has the labels lab1,…,labn\lab_1,\ldots,\lab_n, in the order written; every other type-alias binding is replaced by tycon\tycon alone.

  • A port declaration port var : ty\kw{port}\ \var\ \kw{:}\ \ty is replaced by port var : (out,τ)\kw{port}\ \var\ \kw{:}\ (\smdirout,\tau) for an outgoing port and by port var : (in,τ)\kw{port}\ \var\ \kw{:}\ (\smdirin,\tau) for an incoming one, where τ\tau is the payload type of the port; the direction and the payload type are those that elaboration records in the port environment (Chapter 5, Section 5.4).

  • After number specialisation (Section 6.2), an exposing item var\var naming a top-level variable whose declaration has been copied stands for the items naming var\var and each of the new variables that the copies bind, so that a module that uses var\var at an instance other than the default one finds the copy for that instance.

  • An import import modid\kw{import}\ \modid without as is read as import modid as modid\kw{import}\ \modid\ \kw{as}\ \modid: it provides its own modid\modid as qualifier (Section 3.2).

As everywhere in the semantics, the derived forms of Appendix A have been applied, so the top-level declarations of a module stand in the order of Section A.2; and the imports of a module are the default imports of Figure 11 followed by the imports written in it.

7.2Compound Objects

There are no simple objects beyond those of the Core. The compound objects for the dynamic semantics of Modules, extra to those of the Core (Figure 20), are shown in Figure 21.

CE\dmCE∈\inConEnv\dmConEnv=TyCon→finValEnv= \cls{TyCon}\finmap\ValEnv
(RA,CE,VE) or I(\dmRA,\dmCE,\VE)\ \text{or}\ I∈\inInterface\Interface=Fin TyCon×ConEnv×ValEnv= \Fin\cls{TyCon}\times\dmConEnv\times\ValEnv
ME\ME∈\inModEnv\ModEnv=ModId→finInterface= \cls{ModId}\finmap\Interface
ME or B\ME\ \text{or}\ B∈\inBasis\Basis=ModEnv= \ModEnv
Figure 21: Compound Semantic Objects for Modules

A constructor environment CE\dmCE maps the type constructor tycon\tycon of each custom type to a value environment of its constructors. A dynamic interface (RA,CE,VE)(\dmRA,\dmCE,\VE) records what a module makes available to other modules: VE\VE binds every value it exposes, namely its exposed values and ports, the constructors of each custom type whose constructors it exposes, and the constructor of each record alias it exposes; CE\dmCE maps every custom type that it exposes to the constructors of that type that it exposes, which is the empty map for a type exposed closed; and RA\dmRA is the set of the type constructors tycon\tycon of the record aliases whose constructors it exposes. For a type constructor tycon\tycon we write con=tycon\con=\tycon when con\con is spelt as tycon\tycon, as in Chapter 5: the constructor of a record alias tycon\tycon is bound in VE\VE to the constructor con\con with con=tycon\con=\tycon. A module environment maps each module identifier to the interface of that module, and a dynamic basis is a module environment. Interface, ModEnv and Basis are the dynamic objects of the names that Chapter 5 uses for static objects; Chapter 9 distinguishes them where both are in play.

Projection, injection and modification are as for the Core. In particular “CEofI\dmCE\of I” is the second component of II; B(modid)B(\modid) means ME(modid)\ME(\modid); “VE\VE in Interface\Interface” means (∅,{},VE)(\emptyset,\emptymap,\VE); and interfaces are modified component by component, the set components by union. The interfaces inferred by the rules of this chapter have the following property, on which rule (121) relies.

If (RA,CE,VE)(\dmRA,\dmCE,\VE) is an interface inferred by the rules, then con∈Dom VE\con\in\Dom\VE for every tycon∈RA\tycon\in\dmRA and con=tycon\con=\tycon, and VE(con)=v\VE(\con)=v whenever (CE(tycon))(con)=v(\dmCE(\tycon))(\con)=v.

7.3Merging Environments

Several imports of one module may provide the same qualifier, and the names they provide under it are then all available under that qualifier. Imports are therefore combined by the following modification, which merges, rather than replaces, the environment of a qualifier common to both of its arguments. For environments E1=(QE1,VE1)E_1=(\QE_1,\VE_1) and E2=(QE2,VE2)E_2=(\QE_2,\VE_2),

E1⊞E2  =  (QE, VE1+VE2), E_1\dmmerge E_2 \;=\; (\QE,\ \VE_1+\VE_2),

where Dom QE=Dom QE1∪Dom QE2\Dom\QE=\Dom\QE_1\cup\Dom\QE_2, and QE(modid)\QE(\modid) is QE1(modid)+QE2(modid)\QE_1(\modid)+\QE_2(\modid) if modid∈Dom QE1∩Dom QE2\modid\in\Dom\QE_1\cap\Dom\QE_2, and otherwise whichever of QE1(modid)\QE_1(\modid) and QE2(modid)\QE_2(\modid) is defined. Where both arguments bind a name, the binding of E2E_2 is kept.

7.4Record Constructors

The constructor of a record alias is a function of the fields of the record, taken in the order in which the alias writes them. For n≥1n\geq 1 and distinct labels lab1,…,labn\lab_1,\ldots,\lab_n we extend BasVal with the basic value record(lab1⋯labn)\dmrecord(\lab_1\cdots\lab_n), of arity nn, and extend APPLY\APPLY to it by

APPLY(record(lab1⋯labn), v1⋯vn)  =  {{lab1↦v1,…,labn↦vn}}. \APPLY(\dmrecord(\lab_1\cdots\lab_n),\,v_1\cdots v_n) \;=\; \{\{\lab_1\mapsto v_1,\ldots,\lab_n\mapsto v_n\}\}.

For n=0n=0 we let record()\dmrecord() stand for the empty record {}\emptymap, which is a value but not a basic value, since every basic value has arity at least 1. These values are not bound in the initial basis (Appendix D); they are bound only by the record aliases of modules.

BasVal includes also the values of ports, the basic values outport(var,τ)\effoutport(\var,\tau) and inport(var,τ)\effinport(\var,\tau) for a port name var\var and a payload type τ\tau. They are defined in Chapter 8 (Section 8.7); this chapter uses only the fact that they are basic values.

7.5Top-level Value Groups

A recursive group of top-level values need not consist of functions: the restrictions of Section 3.7 admit any group in which every cycle passes through an occurrence within a lambda expression. The operation Rec \Rec (Section 6.6) gives the bindings of a group only to the closures that the group binds, not to a closure held within a record, a tuple or a constructor value. We have therefore adopted the following translation, under which every member of a group is reached through a function of the unit value.

Let valbind=var1 = exp1 and ⋯ and varn = expn\valbind=\var_1\ \kw{=}\ \expm_1\ \kw{and}\ \cdots\ \kw{and}\ \var_n\ \kw{=}\ \expm_n be a top-level value declaration, and let var1′,…,varn′\var'_1,\ldots,\var'_n be distinct variables that occur nowhere in the program. For a phrase of the Core, phrase∙\dmthunk{\mathit{phrase}} is the phrase obtained from it by replacing simultaneously, for 1≤i≤n1\leq i\leq n,

  • each free occurrence of the atomic expression vari\var_i by the atomic expression (vari′ ())\kw{(}\var'_i\ \kw{()}\kw{)}, and

  • each atomic expression { vari | exprow }\kw{\kwlb}\ \var_i\ \kw{|}\ \exprow\ \kw{\kwrb} in which vari\var_i is free by let vari = vari′ () in { vari | exprow∙ }\kw{let}\ \var_i\ \kw{=}\ \var'_i\ \kw{()}\ \kw{in}\ \kw{\kwlb}\ \var_i\ \kw{|}\ \dmthunk{\exprow}\ \kw{\kwrb},

where “free” is as in Section A.1. These are the only positions at which a variable occurs free in an expression. Then

valbind∙  =  var1′ = \ _ -> exp1∙ and ⋯ and varn′ = \ _ -> expn∙. \dmthunk{\valbind}\;=\; \var'_1\ \kw{=}\ \kw{\textbackslash}\,\kw{\_}\ \kw{->}\ \dmthunk{\expm_1}\ \kw{and}\ \cdots\ \kw{and}\ \var'_n\ \kw{=}\ \kw{\textbackslash}\,\kw{\_}\ \kw{->}\ \dmthunk{\expm_n}.

Every binding of valbind∙\dmthunk{\valbind} is a lambda expression, so Rec \Rec ties the knot for it exactly as for a recursive declaration of the Core, and vari′ ()\var'_i\ \kw{()} then evaluates expi∙\dmthunk{\expm_i}. When no vari\var_i is free in any expj\expm_j, the declaration is not recursive and expi∙=expi\dmthunk{\expm_i}=\expm_i.

7.6Inference Rules

The rules infer sentences of the forms

B⊢phrase⇒A,E⊢phrase⇒A,I⊢phrase⇒A,⊢phrase⇒A, \jdg{B}{\mathit{phrase}}{A},\quad \jdg{E}{\mathit{phrase}}{A},\quad \jdg{I}{\mathit{phrase}}{A},\quad \jdg{}{\mathit{phrase}}{A},

where BB is a basis, EE an environment, II an interface, and AA is the result: a basis with a value environment, a module identifier with an interface, an environment, an interface, a constructor environment with a value environment, or a value environment. Each is pronounced “phrase\mathit{phrase} evaluates to AA”, followed by “in BB”, “in EE” or “in II”. The hypotheses of a rule that are not sentences are its side conditions; some premises are sentences of the Core (Chapter 6). The convention for options is the same as for the Core static semantics.

As in the Core, sentences have no states and there are no exception packets, so every rule is given in full, and the order of the premises of a rule carries no meaning (Section 6.7).

ModulesB⊢module⇒B′,VE\jdg{B}{\modm}{B',\VE}
B⊢imports⇒EE0+E⊢topdec⇒II⊢header⇒(modid,I′)B⊢header imports topdec⇒{modid↦I′}, VEofI\frac{\begin{array}{c}\jdg{B}{\imports}{E}\premsep\jdg{E_0+E}{\topdec}{I}\premsep \jdg{I}{\header}{(\modid,I')}\end{array}}{\begin{array}{c}\jdg{B}{\header\ \imports\ \topdec}{\{\modid\mapsto I'\},\ \VE\of I}\end{array}}
(113)
Comments:
(113)

Here E0E_0 is the environment of Appendix D that binds the list constructor names [] and ::; every module starts from it, as its elaboration starts from π0\pi_0 (rule (46)). The top-level declarations are evaluated in E0E_0 modified by the environment that the imports give, so a name that a module declares replaces, within it, an imported name spelt alike (rule (129)). The basis {modid↦I′}\{\modid\mapsto I'\} holds only what the header exposes; the value environment VEofI\VE\of I of all the module’s own values is the second result, as in the static semantics, because Chapter 9 takes the value of main from it, and main need not be exposed. A module is evaluated once, after the modules it imports, and its top-level values are evaluated then (Chapter 9).

HeadersI⊢header⇒(modid,I′)\jdg{I}{\header}{(\modid,I')}
I⊢explist⇒I′I⊢⟨port⟩ module modid exposing explist⇒(modid,I′)\frac{\begin{array}{c}\jdg{I}{\explist}{I'}\end{array}}{\begin{array}{c}\jdg{I}{\opt{\kw{port}}\ \kw{module}\ \modid\ \kw{exposing}\ \explist}{(\modid,I')}\end{array}}
(114)
Comments:
(114)

The word port has no dynamic content: a port module and a plain module evaluate alike.

ImportsB⊢imports⇒E\jdg{B}{\imports}{E}
B(modid)=I⟨I⊢explist⇒I′⟩B⊢imports⇒EB⊢import modid as modid′ ⟨exposing explist⟩ imports⇒({modid′↦({},VEofI)}, {}⟨+ VEofI′⟩)⊞E\frac{\begin{array}{c}B(\modid)=I\premsep\opt{\jdg{I}{\explist}{I'}}\premsep \jdg{B}{\imports}{E}\end{array}}{\begin{array}{c}B\vdash\kw{import}\ \modid\ \kw{as}\ \modid'\ \opt{\kw{exposing}\ \explist}\ \imports\\ \Rightarrow(\{\modid'\mapsto(\emptymap,\VE\of I)\},\ \emptymap\opt{+\,\VE\of I'})\dmmerge E\end{array}}
(115)
B⊢ ⇒({},{})\frac{\begin{array}{c}\end{array}}{\begin{array}{c}\jdg{B}{\ }{(\emptymap,\emptymap)}\end{array}}
(116)
Comments:
(115)

B(modid)B(\modid) is defined, since a module is evaluated only after every module it imports (Chapter 9). The qualifier modid′\modid' gives access to every value that the imported module exposes, its constructors included; the exposing list makes a part of them available unqualified. The environment of later imports stands on the right of ⊞\dmmerge, so a name exposed by a later import replaces the same name exposed by an earlier one, and in particular a written import replaces a default import. Where elaboration has found an unqualified name ambiguous, the name is not used, so which binding is kept is immaterial.

Exposing ListsI⊢explist⇒I′\jdg{I}{\explist}{I'}
I⊢(..)⇒I\frac{\begin{array}{c}\end{array}}{\begin{array}{c}\jdg{I}{\kw{(..)}}{I}\end{array}}
(117)
I⊢item1⇒I1  ⋯  I⊢itemn⇒InI⊢(item1 , ⋯ , itemn)⇒I1+⋯+In\frac{\begin{array}{c}\jdg{I}{\expitem_1}{I_1}\ \ \cdots\ \ \jdg{I}{\expitem_n}{I_n}\end{array}}{\begin{array}{c}\jdg{I}{\kw{(}\expitem_1\ \kw{,}\ \cdots\ \kw{,}\ \expitem_n\kw{)}} {I_1+\cdots+I_n}\end{array}}
(118)
Comments:
(117)

The sentence I⊢explist⇒I′\jdg{I}{\explist}{I'} is the dynamic counterpart of the interface Expose\Expose of Chapter 5: the values of I′I' are exactly those whose names elaboration admits through explist\explist.

Exposing ItemsI⊢item⇒I′\jdg{I}{\expitem}{I'}
(VEofI)(var)=vI⊢var⇒{var↦v} in Interface\frac{\begin{array}{c}(\VE\of I)(\var)=v\end{array}}{\begin{array}{c}\jdg{I}{\var}{\{\var\mapsto v\}\ \text{in}\ \Interface}\end{array}}
(119)
I⊢(op)⇒(∅,{},{})\frac{\begin{array}{c}\end{array}}{\begin{array}{c}\jdg{I}{\kw{(}\opv\kw{)}}{(\emptyset,\emptymap,\emptymap)}\end{array}}
(120)
tycon∈RAofIcon=tycon(VEofI)(con)=vI⊢tycon⇒({tycon},{},{con↦v})\frac{\begin{array}{c}\tycon\in\dmRA\of I\premsep\con=\tycon\premsep(\VE\of I)(\con)=v\end{array}}{\begin{array}{c}\jdg{I}{\tycon}{(\{\tycon\},\emptymap,\{\con\mapsto v\})}\end{array}}
(121)
tycon∉RAofICE={tycon↦{} ; tycon∈Dom (CEofI)}I⊢tycon⇒(∅,CE,{})\frac{\begin{array}{c}\tycon\notin\dmRA\of I\premsep \dmCE=\{\tycon\mapsto\emptymap\,;\,\tycon\in\Dom(\dmCE\of I)\}\end{array}}{\begin{array}{c}\jdg{I}{\tycon}{(\emptyset,\dmCE,\emptymap)}\end{array}}
(122)
(CEofI)(tycon)=VEI⊢tycon (..)⇒(∅,{tycon↦VE},VE)\frac{\begin{array}{c}(\dmCE\of I)(\tycon)=\VE\end{array}}{\begin{array}{c}\jdg{I}{\tycon\,\kw{(..)}}{(\emptyset,\{\tycon\mapsto\VE\},\VE)}\end{array}}
(123)
Comments:
(119)

The variable is a value or a port.

(120)

An operator is not in the domain of a value environment: its value is given by the operator table OTDYN\OTdyn, and is the same in every module (rule (68)). Exposing or importing an operator therefore binds nothing.

(121)

Rules (121) and (122) cover the one item tycon\tycon, distinguished by whether tycon\tycon is a record alias whose constructor II exposes. The property of Section 7.2 ensures that (VEofI)(con)(\VE\of I)(\con) is then defined. A record alias exposed by name exposes its constructor, so import Geometry exposing (Point) makes Point 1 2 available.

(122)

A custom type exposed without (..) exposes no value, even when one of its constructors is spelt as the type: in a module with type Id = Id Int and header exposing (Id), the constructor Id is not exposed. The type is still exposed, closed: the constructor environment maps it to the empty map, so that an import of Id(..) has a meaning (rule (123)). An alias of a type other than a closed record is in neither RAofI\dmRA\of I nor Dom (CEofI)\Dom(\dmCE\of I), and exposes nothing.

(123)

By elaboration, tycon\tycon names a custom type that II exposes, so (CEofI)(tycon)(\dmCE\of I)(\tycon) is defined; an item tycon (..)\tycon\,\kw{(..)} for an alias is rejected (Chapters 3 and 5). In a header, II is the module’s own interface, which holds every constructor of tycon\tycon. In an import, VE\VE holds the constructors that the imported module exposes, and is the empty map when it exposes tycon\tycon closed: with module A exposing (T), type T = T Int and import A exposing (T(..)), the import makes no constructor available.

Top-level DeclarationsE⊢topdec⇒I\jdg{E}{\topdec}{I}
E⊢valbind∙⇒VEE+Rec VE⊢var1′ ()⇒v1  ⋯  E+Rec VE⊢varn′ ()⇒vnE⊢valbind⇒{var1↦v1,…,varn↦vn} in Interface\frac{\begin{array}{c}\jdg{E}{\dmthunk{\valbind}}{\VE}\\ \jdg{E+\Rec\VE}{\var'_1\ \kw{()}}{v_1}\ \ \cdots\ \ \jdg{E+\Rec\VE}{\var'_n\ \kw{()}}{v_n}\end{array}}{\begin{array}{c}\jdg{E}{\valbind} {\{\var_1\mapsto v_1,\ldots,\var_n\mapsto v_n\}\ \text{in}\ \Interface}\end{array}}
(124)
⊢datbind⇒(CE,VE)E⊢type datbind⇒(∅,CE,VE)\frac{\begin{array}{c}\jdg{}{\datbind}{(\dmCE,\VE)}\end{array}}{\begin{array}{c}\jdg{E}{\kw{type}\ \datbind}{(\emptyset,\dmCE,\VE)}\end{array}}
(125)
⊢typbind⇒(RA,VE)E⊢type alias typbind⇒(RA,{},VE)\frac{\begin{array}{c}\jdg{}{\typbind}{(\dmRA,\VE)}\end{array}}{\begin{array}{c}\jdg{E}{\kw{type alias}\ \typbind}{(\dmRA,\emptymap,\VE)}\end{array}}
(126)
E⊢port var : (out,τ)⇒{var↦outport(var,τ)} in Interface\frac{\begin{array}{c}\end{array}}{\begin{array}{c}\jdg{E}{\kw{port}\ \var\ \kw{:}\ (\smdirout,\tau)} {\{\var\mapsto\effoutport(\var,\tau)\}\ \text{in}\ \Interface}\end{array}}
(127)
E⊢port var : (in,τ)⇒{var↦inport(var,τ)} in Interface\frac{\begin{array}{c}\end{array}}{\begin{array}{c}\jdg{E}{\kw{port}\ \var\ \kw{:}\ (\smdirin,\tau)} {\{\var\mapsto\effinport(\var,\tau)\}\ \text{in}\ \Interface}\end{array}}
(128)
E⊢topdec1⇒(RA1,CE1,VE1)E+VE1⊢topdec2⇒I2E⊢topdec1 ; topdec2⇒(RA1,CE1,VE1)+I2\frac{\begin{array}{c}\jdg{E}{\topdec_1}{(\dmRA_1,\dmCE_1,\VE_1)}\premsep \jdg{E+\VE_1}{\topdec_2}{I_2}\end{array}}{\begin{array}{c}\jdg{E}{\topdec_1\ \kw{;}\ \topdec_2}{(\dmRA_1,\dmCE_1,\VE_1)+I_2}\end{array}}
(129)
Comments:
(124)

Here valbind\valbind is var1 = exp1 and ⋯ and varn = expn\var_1\ \kw{=}\ \expm_1\ \kw{and}\ \cdots\ \kw{and}\ \var_n\ \kw{=}\ \expm_n, and valbind∙\dmthunk{\valbind} and var1′,…,varn′\var'_1,\ldots,\var'_n are as in Section 7.5; the first premise is a sentence of the Core (Value Bindings), and the choice of the new variables does not affect the result. Each vari\var_i is bound to a value obtained once, when its module is evaluated. A reference to vari\var_i within the group evaluates expi∙\dmthunk{\expm_i} again in the same environment, which gives viv_i again, there being no state, unless expi\expm_i relies on the unspecified result of an equality of functions (Section 6.5). A top-level value is thus evaluated once only up to that non-determinism: where expi\expm_i compares functions, a reference to vari\var_i within its group may give another of the values that the equality of functions allows, and so differ from viv_i. Thus with ones = { head = 1, tail = \_ -> ones }, the expression (ones.tail ()).head evaluates to 1. In x = let f _ = x in f () the occurrence of x is delayed, so the restrictions of Section 3.7 admit it, but evaluating var1′ ()\var'_1\ \kw{()} needs var1′ ()\var'_1\ \kw{()} again, without end: no sentence about the declaration can be inferred, and the module has no meaning.

(127)

Rules (127) and (128): the payload type τ\tau comes from elaboration through the reduced syntax; it has no type variables, so the value of a port is the same at every use. Applied to a value, the value of an outgoing port gives a command that sends its encoding at τ\tau; applied to a function, the value of an incoming port gives a subscription (Section 8.7). Port names are unique in a program, so the name identifies the port.

(129)

By the derived forms of Section A.2, topdec\topdec consists of the custom-type group, then the aliases, then the ports and value groups in dependency order, so every declaration is evaluated after each declaration it refers to. Where that order leaves two declarations unordered, either order gives the same result.

Custom-type Bindings⊢datbind⇒(CE,VE)\jdg{}{\datbind}{(\dmCE,\VE)}
⊢conbind⇒VE⟨⊢datbind⇒(CE,VE′)⟩⊢tycon = conbind ⟨and datbind⟩⇒({tycon↦VE}⟨+ CE⟩, VE⟨+ VE′⟩)\frac{\begin{array}{c}\jdg{}{\conbind}{\VE}\premsep\opt{\jdg{}{\datbind}{(\dmCE,\VE')}}\end{array}}{\begin{array}{c}\jdg{}{\tycon\ \kw{=}\ \conbind\ \opt{\kw{and}\ \datbind}} {(\{\tycon\mapsto\VE\}\opt{+\,\dmCE},\ \VE\opt{+\,\VE'})}\end{array}}
(130)
Comments:
(130)

No type names are generated: a custom type has no dynamic content beyond its constructors. The constructors of a module are distinct (Section 3.7), so the modification of VE\VE replaces no binding.

Constructor Bindings⊢conbind⇒VE\jdg{}{\conbind}{\VE}
⟨⊢conbind⇒VE⟩⊢con ⟨| conbind⟩⇒{con↦con}⟨+ VE⟩\frac{\begin{array}{c}\opt{\jdg{}{\conbind}{\VE}}\end{array}}{\begin{array}{c}\jdg{}{\con\ \opt{\kw{|}\ \conbind}}{\{\con\mapsto\con\}\opt{+\,\VE}}\end{array}}
(131)
Comments:
(131)

The constructor value con\con awaits all arity(con)\arity(\con) of its arguments; a constructor of arity 0 is thus a complete value. Constructors spelt alike in different modules give equal constructor values, which never meet in one rule, since they have different types (Section 6.3).

Alias Bindings⊢typbind⇒(RA,VE)\jdg{}{\typbind}{(\dmRA,\VE)}
⟨con=tycon⟩⊢tycon ⟨= {lab1, ⋯, labn}⟩⇒(∅⟨∪ {tycon}⟩, {}⟨+ {con↦record(lab1⋯labn)}⟩)\frac{\begin{array}{c}\opt{\con=\tycon}\end{array}}{\begin{array}{c}\vdash\tycon\ \opt{\kw{=}\ \kw{\kwlb}\lab_1\kw{,}\ \cdots\kw{,}\ \lab_n\kw{\kwrb}}\\ \Rightarrow(\emptyset\opt{\cup\,\{\tycon\}},\ \emptymap\opt{+\,\{\con\mapsto\dmrecord(\lab_1\cdots\lab_n)\}})\end{array}}
(132)
Comments:
(132)

Here n≥0n\geq 0, and by the syntactic restrictions the labels are distinct. The constructor takes the fields in the order in which the alias writes them: with type alias P = { y : Int, x : Int }, P 1 2 evaluates to { y = 1, x = 2 }. An alias of the empty record binds its name to the empty record itself (Section 7.4). An alias of any other type binds nothing, and its type constructor is not in RA\dmRA; so rule (126) records in RA\dmRA exactly the record aliases.

Discussions

Discuss this chapter·Search the discussions on GitHub

Discussions are on GitHub; one about this chapter has [ch:dynamic-modules] 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.