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
| Restriction | Statement |
|---|---|
| core-escape-unicode | In \u{}, 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-characters | A 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-separated | A 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-items | The following constructs require two items to be adjacent, that is, to have no whitespace or comment between them: |
| core-layout-rule | Every item of a phrase is indented, except the items that the constructs below require to be aligned or at the margin. |
| core-operator-chain | If and () 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 twice. |
| core-pattern-row-label-only Records | No pattern row of a program has the form : a program writes each component of a record pattern as a label alone, the derived form of Appendix A, whose equivalent form binds the variable spelt as the label. |
| core-record-update-form Records | In a record update 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 (Appendix A), is a , 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 twice. |
| core-no-shadowing Patterns and bound variables | No binding site may bind a 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 is followed directly by a definition of the same , 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
| Restriction | Statement |
|---|---|
| modules-ports | In a module, the contains a port declaration only if the header is a port module header, and the of a module with a port module header contains at least one port declaration. |
| modules-header | Every module begins with a header, module exposing or port module exposing . |
| modules-import-alias | In an import, the after as consists of a single upper-case identifier. |
| modules-basics-qualifier | The qualifier Basics is provided only by an import of the module Basics: an import requires to be Basics. |
| modules-no-operator-exposing | An item () occurs only in the exposing list of an import: a module declares no operator, so it has none to expose. |
| modules-header-exposing | In the exposing list of a header, each item is bound by a value declaration or a port declaration of the module’s ; each item is the of a or a of the ; and each item is the of a , never of a . |
| modules-exposing-distinct | No two items of the exposing list of a header may have the same identifier; thus and do not both occur. |
| modules-no-top-pattern | No value declaration of a may contain a binding other than one of the form ; there is no pattern binding at the top level. |
| modules-values-distinct | No may bind the same twice by its value declarations and port declarations together. |
| modules-types-distinct | No may declare the same twice: custom types and aliases share one name space. |
| modules-constructors-distinct | No may declare the same twice. |
| modules-no-shadowing | No variable bound within an expression of a (a parameter of a lambda, a variable of a pattern, or a variable bound in a let) may be a bound by a value declaration or a port declaration of that , wherever the declaration stands. |
| modules-tyvarseq-distinct | No may contain the same twice. |
| modules-custom-type-tyvars | In a custom-type binding , every occurring in , including the extension variable of a record type, occurs in . |
| modules-alias-tyvars | In a type-alias binding , the contains exactly the type variables occurring in , including extension variables of record types: an alias has no unused parameter. |
| modules-alias-not-recursive | No alias may be recursive. |
| modules-value-recursion | An occurrence of a variable in an expression is delayed if it lies within a lambda expression in , and direct otherwise. |
| modules-program | The following restrictions concern a program, and Chapter 9 imposes them. |
4Static Semantics for the Core
| Restriction | Statement |
|---|---|
| core-irredundancy | Irredundancy. In a match whose patterns elaborate with type , each must cover some inhabitant of that no with covers. |
| core-exhaustiveness | Exhaustiveness. In a match as above, every inhabitant of must be covered by some . |
9Programs
| Restriction | Statement |
|---|---|
| program-modules-distinct | No 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-order | Each module of a program imports only modules of the initial basis and modules that stand before it in the program. |
| program-modules-reachable | Every module of a program other than the main module is imported, directly or through other modules, by the main module. |
| program-main | The 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.