Elm Exactly
A Standard Definition of Elm?Draft version 0.4 / Restrictions

Restrictions

The conditions on programs that are stated apart from the grammar and the inference rules: the syntactic restrictions on modules and programs, and the further restrictions of the static semantics. A program that breaks one is not legal. Like a rule, each has a page at an address made from its name, which does not change between editions.

2Syntax of the Core

RestrictionStatement
core-escape-unicodeIn \u{hh}, hh is a sequence of four, five or six hexadecimal digits whose value is a Unicode scalar value, that is, at most 10FFFF and outside the surrogate range D800 to DFFF.
core-identifier-charactersA lower identifier is a letter of category Ll (which includes a, …, z) followed by a sequence of zero or more inner characters: letters, decimal digits and underbars _.
core-constant-separatedA special constant, and the reserved word _, may not be followed immediately by an inner character, and the digits of an integer constant may be followed immediately by . only as part of a fraction; so 12abc, 1.x and _x are not sequences of items.
core-adjacent-itemsThe following constructs require two items to be adjacent, that is, to have no whitespace or comment between them:
core-layout-ruleEvery item of a phrase is indented, except the items that the constructs below require to be aligned or at the margin.
core-operator-chainIf opj\opv_j and opl\opv_l (j<lj < l) of a chain have equal precedence and no operator of lower precedence stands between them, then either both associate to the left and the chain groups to the left, or both associate to the right and it groups to the right; otherwise the chain is not a phrase of the language.
core-row-labels-distinct
Records
No expression row, pattern row or type-expression row may contain the same lab\lab twice.
core-pattern-row-label-only
Records
No pattern row of a program has the form lab = var\lab\ \kw{=}\ \var: a program writes each component of a record pattern as a label alone, the derived form of Appendix A, whose equivalent form lab = var\lab\ \kw{=}\ \var binds the variable spelt as the label.
core-record-update-form
Records
In a record update { var | exprow }\kw{\kwlb}\ \var\ \kw{|}\ \exprow\ \kw{\kwrb} the item before | is a variable that is not qualified, and at least one expression row follows |; the grammar gives this shape, and an extensible record type expression likewise has at least one row.
core-field-selection
Records
In a field selection atexp.lab\atexp\kw{.}\lab (Appendix A), atexp\atexp is a longvar\longvar, a record, a record update, a field selection, or a phrase that begins with (: a parenthesised expression, a tuple, the unit or an operator value.
core-binding-site-distinct
Patterns and bound variables
No binding site may bind the same var\var twice.
core-no-shadowing
Patterns and bound variables
No binding site may bind a var\var that is already bound by a binding site in whose scope it lies.
core-no-float-pattern
Patterns and bound variables
No float constant may occur in a pattern.
core-annotation-placement
Value bindings
In source text each annotation var : ty\var\ \kw{:}\ \ty is followed directly by a definition of the same var\var, laid out as Section 2.6 requires.
core-let-recursion
Value bindings
In a let, a definition refers to a definition (possibly itself) if a variable that the second binds occurs in the first.

3Syntax of Modules

RestrictionStatement
modules-portsIn a module, the topdec\topdec contains a port declaration only if the header is a port module header, and the topdec\topdec of a module with a port module header contains at least one port declaration.
modules-headerEvery module begins with a header, module modid\modid exposing explist\explist or port module modid\modid exposing explist\explist.
modules-import-aliasIn an import, the modid\modid after as consists of a single upper-case identifier.
modules-basics-qualifierThe qualifier Basics is provided only by an import of the module Basics: an import import modid as Basics\kw{import}\ \modid\ \kw{as}\ \kw{Basics} requires modid\modid to be Basics.
modules-no-operator-exposingAn item (op\opv) occurs only in the exposing list of an import: a module declares no operator, so it has none to expose.
modules-header-exposingIn the exposing list of a header, each item var\var is bound by a value declaration or a port declaration of the module’s topdec\topdec; each item tycon\tycon is the tycon\tycon of a datbind\datbind or a typbind\typbind of the topdec\topdec; and each item tycon (..)\tycon\,\kw{(..)} is the tycon\tycon of a datbind\datbind, never of a typbind\typbind.
modules-exposing-distinctNo two items of the exposing list of a header may have the same identifier; thus tycon\tycon and tycon (..)\tycon\,\kw{(..)} do not both occur.
modules-no-top-patternNo value declaration of a topdec\topdec may contain a binding other than one of the form var ⟨: ty⟩ = exp\var\ \opt{\kw{:}\ \ty}\ \kw{=}\ \expm; there is no pattern binding at the top level.
modules-values-distinctNo topdec\topdec may bind the same var\var twice by its value declarations and port declarations together.
modules-types-distinctNo topdec\topdec may declare the same tycon\tycon twice: custom types and aliases share one name space.
modules-constructors-distinctNo topdec\topdec may declare the same con\con twice.
modules-no-shadowingNo variable bound within an expression of a topdec\topdec (a parameter of a lambda, a variable of a pattern, or a variable bound in a let) may be a var\var bound by a value declaration or a port declaration of that topdec\topdec, wherever the declaration stands.
modules-tyvarseq-distinctNo tyvarseq\tyvarseq may contain the same tyvar\tyvar twice.
modules-custom-type-tyvarsIn a custom-type binding tycon tyvarseq = conbind\tycon\ \tyvarseq\ \kw{=}\ \conbind, every tyvar\tyvar occurring in conbind\conbind, including the extension variable of a record type, occurs in tyvarseq\tyvarseq.
modules-alias-tyvarsIn a type-alias binding tycon tyvarseq = ty\tycon\ \tyvarseq\ \kw{=}\ \ty, the tyvarseq\tyvarseq contains exactly the type variables occurring in ty\ty, including extension variables of record types: an alias has no unused parameter.
modules-alias-not-recursiveNo alias may be recursive.
modules-value-recursionAn occurrence of a variable in an expression exp\expm is delayed if it lies within a lambda expression in exp\expm, and direct otherwise.
modules-programThe following restrictions concern a program, and Chapter 9 imposes them.

4Static Semantics for the Core

RestrictionStatement
core-irredundancyIrredundancy. In a match pat1 -> exp1 ; ⋯ ; patn -> expn\pat_1\ \kw{->}\ \expm_1\ \kw{;}\ \cdots\ \kw{;}\ \pat_n\ \kw{->}\ \expm_n whose patterns elaborate with type τ\tau, each patj\pat_j must cover some inhabitant of τ\tau that no pati\pat_i with i<ji < j covers.
core-exhaustivenessExhaustiveness. In a match as above, every inhabitant of τ\tau must be covered by some pati\pat_i.

9Programs

RestrictionStatement
program-modules-distinctNo two modules of a program have the same module identifier, and no module of a program has the identifier of a module of the initial basis (Appendix C).
program-import-orderEach module of a program imports only modules of the initial basis and modules that stand before it in the program.
program-modules-reachableEvery module of a program other than the main module is imported, directly or through other modules, by the main module.
program-mainThe main module has a top-level value declaration that binds main.

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.