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

2Syntax of the Core

2.1Reserved Words

The following are the reserved words of Standard Elm. They may not be used as identifiers or as operators.

ascaseelseexposingifimportin
letmoduleofportthentypewhere
( )[ ]{ }, .: =| ->\ _

The words exposing, import, module, port and type are used by Modules (Chapter 3). The word where is used by no phrase of Standard Elm: it belongs to the headers of effect modules, which are kernel-only syntax (Section 2.7). The words alias, infix, left, right, non, effect, command and subscription are not reserved; alias serves as a terminal only directly after type (Chapter 3), and elsewhere each of them is an identifier.

2.2Special Constants

Source text is a sequence of Unicode characters. A decimal digit is one of 0, …, 9; a hexadecimal digit is a decimal digit or one of a, …, f, A, …, F.

An integer constant (in decimal notation) is a non-empty sequence of decimal digits that does not begin with 0 unless it is 0 itself. An integer constant (in hexadecimal notation) is 0x followed by a non-empty sequence of hexadecimal digits. No integer constant carries a sign: a negated integer is a derived form (Section 2.5). An integer constant denotes a non-negative integer; its value as an Int is that integer normalised into the implementation’s Int range by norm\norm, the normalisation of Int arithmetic, so that every integer constant has a value in IntRange\IntRange (Appendix E). Examples: 0 42 0x1F 0xffffffff. Non-examples: 007 0X1F 1_000 0b101.

\nline feed (U+000A)
\rcarriage return (U+000D)
\thorizontal tab (U+0009)
\""
\''
\\\
\u{hh}the character with code point hh, read in hexadecimal
Figure 1: Escape Sequences

Tested by: AstralCharLiteralTest, CharAstralRecordFieldTest, CharLiteralSurrogateEscapeTest, CharUnicodeTest, ParseErrorStringEscapeTooFewDigitsTest, ParseErrorStringEscapeUnclosedTest, StandardA8SurrogateEscapeTest

A float constant is an integer constant in decimal notation followed by a fraction, by an exponent, or by a fraction and then an exponent. A fraction is . followed by a non-empty sequence of decimal digits; an exponent is e or E, then optionally + or -, then a non-empty sequence of decimal digits. The constant 0 may be followed by a fraction but not directly by an exponent. A float constant denotes the rational number that it writes in decimal notation. Examples: 0.5 3.14 6.02e23 1E-3 0.0e1. Non-examples: .5 1. 1.e5 0e5.

A character constant is a single quote ', then either one character other than ', \ and line feed, or one escape sequence, then a single quote. It denotes the character it contains, or the character its escape sequence denotes. Thus '' and 'ab' are not constants.

A string constant (single-line) is a double quote ", then a sequence of zero or more characters other than ", \ and line feed, and escape sequences, then a double quote. Three double quotes """ always begin a multi-line string constant, so "" is the empty string only when no third " follows it. A string constant (multi-line) is """, then a sequence of characters other than \, and escape sequences, that does not contain """, then """. The first """ after the opening one closes the constant; any further " immediately after it begins a new item. Line feeds and carriage returns inside a multi-line string constant are characters of the string, and so is a line feed directly after the opening """. A string constant denotes the sequence of characters it contains, each escape sequence standing for the character it denotes.

Each escape sequence begins with \ and stands for one character. The escape sequences are shown in Figure 1, subject to this restriction:

  • In \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. No other sequence beginning with \ is an escape sequence.

    core-escape-unicode

A tab character may occur, unescaped, in a character or string constant. How a character is represented as a value is an implementation parameter (Appendix E).

We denote by SCon\cls{SCon} the class of special constants, that is, the integer, float, character and string constants; we use scon\scon to range over SCon\cls{SCon}.

2.3Comments

A line comment is -- and the characters after it up to the end of the line. A block comment is any character sequence within comment brackets {- -} in which comment brackets are properly nested. No space is allowed between the two characters of a comment bracket. A program in which a {- is unmatched is not a phrase of the language. A tab character may occur in a line comment but not in a block comment.

A comment bracket {- directly followed by | begins a doc comment, which extends, with comment brackets nested as in a block comment, to its matching -}. A doc comment is not a comment: it is an item of the grammar of Modules, which admits it only after a module header and before a top-level declaration (Chapter 3). No doc comment occurs in a Core phrase.

2.4Identifiers

The classes of identifiers for the Core are shown in Figure 2. We use var\var, tyvar\tyvar and so on to range over Var\cls{Var}, TyVar\cls{TyVar}, etc. For each class marked “long” there is a class of long identifiers: LongVar\cls{LongVar}, LongCon\cls{LongCon} and LongTyCon\cls{LongTyCon}, over which longvar\longvar, longcon\longcon and longtycon\longtycon range. Their syntax is

longvar\longvar::=var\varidentifier
modid.var\modid\kw{.}\varqualified identifier
longcon\longcon::=con\conidentifier
modid.con\modid\kw{.}\conqualified identifier
longtycon\longtycon::=tycon\tyconidentifier
modid.tycon\modid\kw{.}\tyconqualified identifier

with no space or comment on either side of each .. Throughout this document the term “identifier”, occurring without an adjective, refers to an identifier that is not qualified.

A letter is a character of one of the Unicode general categories Lu, Ll, Lt, Lm and Lo; the version of the Unicode standard that assigns these categories is an implementation parameter (Appendix E). The identifiers are formed as this restriction states:

  • 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 _. An upper identifier is a letter of category Lu or Lt (which include A, …, Z) followed by a sequence of zero or more inner characters. A letter of category Lm or Lo may continue an identifier but not begin one, and no identifier begins with _. In either case reserved words are excluded, and no component of a long identifier may be a reserved word: thus List.if is not a long identifier.

    core-identifier-characters

An operator is a non-empty sequence of the symbols

+ - * / = . < > : & | ^ ? % !

that is not a reserved word. This means that =, :, | and -> are not operators, but ==, ::, || and |> are. Operators are never qualified.

A variable var\var, a type variable tyvar\tyvar and a record label lab\lab are lower identifiers. A constructor con\con and a type constructor tycon\tycon are upper identifiers. A module identifier modid\modid is a non-empty sequence of upper identifiers separated by ., with no space or comment around each .. A type variable whose name begins with number, comparable, appendable or compappend is constrained to a class of types (Section 4.4).

var\varVar\cls{Var}value variableslong
con\conCon\cls{Con}value constructorslong
tyvar\tyvarTyVar\cls{TyVar}type variables
tycon\tyconTyCon\cls{TyCon}type constructorslong
lab\labLab\cls{Lab}record labels
modid\modidModId\cls{ModId}module identifiers
op\opvOp\cls{Op}operators
Figure 2: Identifiers

The classes Var\cls{Var}, TyVar\cls{TyVar} and Lab\cls{Lab} share the lower identifiers, and Con\cls{Con}, TyCon\cls{TyCon} and ModId\cls{ModId} the upper identifiers. The syntax class of an occurrence of an identifier in a Core phrase is determined thus:

  1. An upper identifier immediately followed by . is a component of a module identifier. The following rules assume that all occurrences of module identifiers have been removed.

  2. Within a type expression, a lower identifier is a type variable and an upper identifier is a type constructor.

  3. At the start of a component of a record expression, record update, record type or record pattern, and immediately after the . of a field selection or field accessor (Appendix A), a lower identifier is a record label. A record label that forms a whole component of a record pattern, the derived pattern row of Appendix A, is also a variable, bound by that pattern.

  4. Elsewhere, a lower identifier is a variable and an upper identifier is a constructor.

For the remainder of this document we shall therefore assume that the classes are all disjoint.

2.5Lexical Analysis

Each item of lexical analysis is either a reserved word, a special constant, a long identifier, an operator, or a doc comment. Comments and the whitespace characters (space, line feed and carriage return) separate items and are otherwise ignored, except that the layout rule depends on the column at which each item begins (Section 2.6) and that the constructs listed below depend on whether two items are separated. A tab character may occur only within a line comment or within a character or string constant. Where the remaining text begins with -- or {-, a comment or doc comment is taken. Otherwise, at each stage the longest next item is taken. Thus types is an identifier, not type followed by s; within a run of symbols -- is part of an operator and begins no comment, so a*-b contains the single operator *-, and 2^-1 the operator ^-. Items are also subject to these restrictions:

  • 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-constant-separated
  • The following constructs require two items to be adjacent, that is, to have no whitespace or comment between them:

    • the parentheses of the unit (), and the operator and parentheses of an operator value (op\opv);

    • the . of a long identifier and the items on either side of it;

    • the . of a field selection atexp\atexp.lab\lab and the items on either side of it, and the . of a field accessor .lab\lab and the label after it. A . adjacent to a following label is the . of a field selection only if it is adjacent to the item before it and that item ends an atomic expression that may precede a field selection (Section 2.10); otherwise it begins a field accessor (Appendix A). In particular a . directly after a field accessor begins a field accessor;

    • the negation symbol and the atomic expression it negates.

    core-adjacent-items

An item - is a negation symbol when it is adjacent to a following atomic expression and either it begins an operand of an expression, or it follows an operand from which it is separated by whitespace or a comment. A negation symbol negates the atomic expression after it, and no more; in the second case the negated expression is an argument of an application. Every other - is the operator -. Thus f -x applies f to the negation of x, while a - b and a-b are subtractions; -f x applies the negation of f to x; and (-) is the operator value of subtraction. Negation is a derived form (Appendix A).

2.6Layout

The phrase structure of Elm depends on indentation. Source text is divided into lines by line feeds. The column of an item is one more than the number of characters that precede it on its line, where a carriage return counts as no character. Each item is read under an indentation, a natural number ii. An item whose column is cc is

  • indented if c>ic > i and c>1c > 1;

  • aligned if c=ic = i;

  • at the margin if c=1c = 1.

These tests concern only the column at which an item begins: where the item before it ended, for instance on a later line than it began, is irrelevant. The layout rule is this restriction:

  • Every item of a phrase is indented, except the items that the constructs below require to be aligned or at the margin.

    core-layout-rule

Only these constructs change the indentation; elsewhere an item is read under the indentation of the phrase that contains it.

  1. Top-level declarations (Chapter 3). The first item of each top-level declaration is at the margin, and its remaining items are read under the indentation 00; so each of them lies in column 22 or beyond.

  2. Let expressions. Let kk be the column of the reserved word let. The item after let has a column dd with d>kd > k and d>1d > 1, and dd is the indentation under which the definitions of the let are read: the first item of each later definition, and of each annotation, is aligned, and every other item of the definitions is indented. The reserved word in and the body after it are read under the indentation in force at let.

  3. Case expressions. The items of case exp\expm of and the first item of the first match rule are read under the indentation in force at case. The column pp of that first item is the indentation under which the match is read: the first item of each later match rule is aligned, and every other item of the match is indented.

An annotation var : ty\var\ \kw{:}\ \ty is followed directly by a definition of the same var\var, whose first item has the column of the annotation’s first item: at the margin at top level, aligned in a let. Each construct extends as far as possible: it takes in every following item that passes the test that applies to it and continues the phrase, and it ends before the first item that does not. Thus two definitions of one let, or two match rules of one case, never begin on the same line, while let x = 1 in x is a phrase on one line.

2.7Infixed Operators

An operator op\opv has a fixity: a precedence, which is one of the digits 0, …, 9, and an associativity, which is left, right or non. Operators are declared, with their fixities, only by kernel-only syntax. Kernel-only syntax, namely operator declarations, effect module headers and references to Elm.Kernel modules, lies outside Standard Elm. No program can therefore declare an operator, and the operators are those of the initial basis, the same in every program. Their fixities are shown in Figure 3; the operator table of the initial basis gives the meaning of each, its type scheme in Appendix C and its value in Appendix D. Operators of library modules beyond the initial basis are outside this definition.

PrecedenceLeftRightNon
9<<>>
8^
7* / //
6+ -
5++ ::
4== /= < > <= >=
3&&
2||
0|><|
Figure 3: Fixities of the Operators of the Initial Basis

Tested by: InfixAssocLeftArithTest, InfixAssocPipesTest, InfixAssocRightConsAppendTest, InfixAssocRightPowTest, InfixLastOperandAnyExprTest, InfixMixedAssocComposeTest, InfixMixedAssocPipesTest, InfixNegatedOperandTest, InfixNonAssocCompareTest, InfixNonAssocEqTwiceTest, InfixNonAssocSeparatedLegalTest, InfixPrecAddOverConsTest, InfixPrecAndOverOrTest, InfixPrecAppendOverEqTest, InfixPrecApplicationFirstTest, InfixPrecCompareOverAndTest, InfixPrecComposeOverPipeTest, InfixPrecMulOverAddTest, InfixPrecOrOverPipeTest, InfixPrecPowOverMulTest

An expression of the form exp0 op1 exp1 ⋯ opn expn\expm_0\ \opv_1\ \expm_1\ \cdots\ \opv_n\ \expm_n (n≥1n \geq 1), in which each opj\opv_j is an operator and each operand expj\expm_j is an application or an atomic expression, possibly negated, except that the last operand may be any expression, is an operator chain. Application binds more tightly than any operator. A chain is grouped so that an operator of higher precedence binds more tightly than one of lower precedence, subject to this restriction:

  • If 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-operator-chain

Precisely, a chain is the infixed application exp′ opj exp′′\expm'\ \opv_j\ \expm'' in which opj\opv_j has the least precedence in the chain and is, among the operators of that precedence, the rightmost if they associate to the left and the leftmost if they associate to the right; exp′\expm' and exp′′\expm'' are the chains, or single operands, to the left and right of opj\opv_j, grouped by the same rule. For example,

a |> f |> gparses as(a |> f) |> g
f <| g <| aparses asf <| (g <| a)
x :: ys ++ zsparses asx :: (ys ++ zs)
a < b == cis illegal
f << g >> his illegal

An operator value (op\opv) is an atomic expression that denotes the operator op\opv as a value; it is the only way to use an operator other than in a chain. There are no sections, and no operator is qualified. The infixed application exp1 op exp2\expm_1\ \opv\ \expm_2 is a derived form (Appendix A); so are the infixed forms of && and ||, which evaluate their second operand only when needed, whereas the operator values (&&) and (||) are ordinary functions. In the semantic rules every chain has been grouped and every infixed application replaced by its equivalent form, since fixity affects only parsing.

2.8Derived Forms

Many syntactic forms of Elm have a meaning that is given by translation into a smaller set of forms, called the bare language. Among them are infixed application, negation, conditional expressions, list expressions with elements, list patterns with elements, pattern rows written as a label alone, field selection and field accessors, lambda expressions and function bindings with parameters beyond the first, and let expressions with several definitions. These derived forms, and their equivalent forms in the bare language, are given in Appendix A. Appendix B collects the bare and derived syntax into one grammar.

2.9Grammar

The phrase classes for the Core are shown in Figure 4. We use the variable atexp\atexp to range over AtExp\cls{AtExp}, etc. The grammatical rules for the Core are shown in Figures 5, 6 and 7.

AtExp\cls{AtExp}atomic expressions
ExpRow\cls{ExpRow}expression rows
Exp\cls{Exp}expressions
Match\cls{Match}matches
MRule\cls{MRule}match rules
Dec\cls{Dec}declarations
ValBind\cls{ValBind}value bindings
AtPat\cls{AtPat}atomic patterns
PatRow\cls{PatRow}pattern rows
Pat\cls{Pat}patterns
Ty\cls{Ty}type expressions
TyRow\cls{TyRow}type-expression rows
Figure 4: Core Phrase Classes

The following conventions are adopted in presenting the grammatical rules, and in their interpretation:

  • The brackets ⟨ ⟩\opt{\ } enclose optional phrases.

  • Alternative forms for each phrase class are in order of decreasing precedence. L (resp. R) means left (resp. right) association.

  • The phrases \ atpat -> exp\kw{\textbackslash}\,\atpat\ \kw{->}\ \expm, case exp of match\kw{case}\ \expm\ \kw{of}\ \match and let dec in exp\kw{let}\ \dec\ \kw{in}\ \expm extend as far right as the layout rule allows (Section 2.6). Such a phrase is written in parentheses when it is the argument of an application, or an operand of an operator chain other than the last.

  • In a type construction longtycon ty1 ⋯ tyn\longtycon\ \ty_1\ \cdots\ \ty_n with n≥1n \geq 1, each argument tyj\ty_j is a type variable, a type construction without arguments, a record type expression, a unit or tuple type expression, or a parenthesised type expression; thus Maybe List a gives Maybe two arguments. Type construction binds more tightly than ->.

  • In patterns, a constructed pattern binds more tightly than ::, and :: more tightly than as; so x :: xs as l is a layered pattern whose pattern is x :: xs. The :: of a pattern always denotes the list constructor of the initial basis. There is no negated constant in a pattern.

  • The separator ; between match rules and the connective and between value bindings are abstract syntax: neither is an item of source text, and and is not a reserved word. In source text the match rules of a match, and the definitions of a let, are separated by layout (Section 2.6). Likewise the annotated value binding var : ty = exp\var\ \kw{:}\ \ty\ \kw{=}\ \expm is written in source text as the annotation var : ty\var\ \kw{:}\ \ty followed by the definition var = exp\var\ \kw{=}\ \expm.

  • In the bare language the declaration of a let is a single value binding whose members form one group; a let with several definitions is a derived form. A value binding atpat = exp\atpat\ \kw{=}\ \expm in which atpat\atpat is a variable is read by the first alternative for valbind\valbind.

  • Tuples have exactly two or three components.

atexp\atexp::=scon\sconspecial constant
longvar\longvarvalue variable
longcon\longconvalue constructor
(op)\kw{(}\opv\kw{)}operator value
()\kw{()}unit
( exp1 , exp2 ⟨, exp3⟩ )\kw{(}\ \expm_1\ \kw{,}\ \expm_2\ \opt{\kw{,}\ \expm_3}\ \kw{)}tuple
[ ]\kw{[}\ \kw{]}empty list
{ ⟨exprow⟩ }\kw{\kwlb}\ \opt{\exprow}\ \kw{\kwrb}record
{ var | exprow }\kw{\kwlb}\ \var\ \kw{|}\ \exprow\ \kw{\kwrb}record update
let dec in exp\kw{let}\ \dec\ \kw{in}\ \expmlocal declaration
( exp )\kw{(}\ \expm\ \kw{)}parentheses
exprow\exprow::=lab = exp ⟨, exprow⟩\lab\ \kw{=}\ \expm\ \opt{\kw{,}\ \exprow}expression row
exp\expm::=atexp\atexpatomic
exp atexp\expm\ \atexpapplication (L)
\ atpat -> exp\kw{\textbackslash}\,\atpat\ \kw{->}\ \expmfunction
case exp of match\kw{case}\ \expm\ \kw{of}\ \matchcase analysis
match\match::=mrule ⟨; match⟩\mrule\ \opt{\kw{;}\ \match}match
mrule\mrule::=pat -> exp\pat\ \kw{->}\ \expmmatch rule
dec\dec::=valbind\valbindvalue declaration
valbind\valbind::=var ⟨: ty⟩ = exp ⟨and valbind⟩\var\ \opt{\kw{:}\ \ty}\ \kw{=}\ \expm\ \opt{\kw{and}\ \valbind}variable binding
atpat = exp\atpat\ \kw{=}\ \expmdestructuring binding
Figure 5: Grammar: Expressions, Matches, Declarations and Bindings

Tested by: BadTupleATupleOfFourTest, InfixIfExtendsRightTest, InfixNoQualifiedOperatorTest, InfixNoSectionLeftTest, InfixNoSectionRightTest

atpat\atpat::=_\kw{\_}wildcard
scon\sconspecial constant
var\varvariable
longcon\longconconstructor
()\kw{()}unit
( pat1 , pat2 ⟨, pat3⟩ )\kw{(}\ \pat_1\ \kw{,}\ \pat_2\ \opt{\kw{,}\ \pat_3}\ \kw{)}tuple
[ ]\kw{[}\ \kw{]}empty list
{ ⟨patrow⟩ }\kw{\kwlb}\ \opt{\patrow}\ \kw{\kwrb}record
( pat )\kw{(}\ \pat\ \kw{)}parentheses
patrow\patrow::=lab = var ⟨, patrow⟩\lab\ \kw{=}\ \var\ \opt{\kw{,}\ \patrow}pattern row
pat\pat::=atpat\atpatatomic
longcon atpat1 ⋯ atpatn\longcon\ \atpat_1\ \cdots\ \atpat_nconstructed pattern (n≥1n \geq 1)
pat1 :: pat2\pat_1\ \kw{::}\ \pat_2list construction (R)
pat as var\pat\ \kw{as}\ \varlayered
Figure 6: Grammar: Patterns

Tested by: ParseErrorCasePatternUnfinishedTest

ty\ty::=tyvar\tyvartype variable
{ ⟨tyrow⟩ }\kw{\kwlb}\ \opt{\tyrow}\ \kw{\kwrb}record type expression
{ tyvar | tyrow }\kw{\kwlb}\ \tyvar\ \kw{|}\ \tyrow\ \kw{\kwrb}extensible record type expression
()\kw{()}unit type expression
( ty1 , ty2 ⟨, ty3⟩ )\kw{(}\ \ty_1\ \kw{,}\ \ty_2\ \opt{\kw{,}\ \ty_3}\ \kw{)}tuple type expression
longtycon ty1 ⋯ tyn\longtycon\ \ty_1\ \cdots\ \ty_ntype construction (n≥0n \geq 0)
ty -> ty′\ty\ \kw{->}\ \ty'function type expression (R)
( ty )\kw{(}\ \ty\ \kw{)}parentheses
tyrow\tyrow::=lab : ty ⟨, tyrow⟩\lab\ \kw{:}\ \ty\ \opt{\kw{,}\ \tyrow}type-expression row
Figure 7: Grammar: Type Expressions

Tested by: TypeExprUnitAppliedTest

2.10Syntactic Restrictions

The restrictions below are conditions on a program as it is written, before any derived form is replaced by its equivalent form; where a restriction names a derived form, the form is that of Appendix A. A program that breaks one of them is not a phrase of the language.

Records.

  • No expression row, pattern row or type-expression row may contain the same lab\lab twice. This applies to the expression row of a record update.

    core-row-labels-distinct
  • 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. The bare form exists so that number specialisation (Chapter 6) can give the variable of a row a new name while keeping its label.

    core-pattern-row-label-only
  • 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-record-update-form
  • 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. A field accessor is never followed by a field selection: in .lab1.lab2\kw{.}\lab_1\kw{.}\lab_2 the second . begins a second field accessor, so the phrase is the application of .lab1\kw{.}\lab_1 to .lab2\kw{.}\lab_2. Likewise "s".x is the application of a string constant to the field accessor .x.

    core-field-selection

Patterns and bound variables. The variable of a pattern row is the var\var of a row lab = var\lab\ \kw{=}\ \var and, for a row written as a label alone (Appendix A), the variable spelt as its label. The variables bound by a pattern are the variables that occur in it outside its pattern rows, the variables of its pattern rows, and the variables after its occurrences of as. the following: the parameters of a lambda expression, taken together; the parameters of a function binding, taken together; the pattern of a match rule; the pattern of a destructuring binding; and the definitions of one let, taken together, which bind the variables they define and the variables their destructuring patterns bind. The scope of a binding site is the body of the lambda expression, the right-hand side of the function binding, the expression of the match rule, or, for a destructuring binding and for the definitions of a let, the definitions of that let and its body.

  • No binding site may bind the same var\var twice.

    core-binding-site-distinct
  • No binding site may bind a var\var that is already bound by a binding site in whose scope it lies. Constructors, type constructors and type variables are not subject to this restriction.

    core-no-shadowing
  • No float constant may occur in a pattern.

    core-no-float-pattern

The number of arguments in a constructed pattern is not restricted here: a constructed pattern with too few or too many arguments for its constructor does not elaborate (Chapter 4).

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-annotation-placement
  • In a let, a definition refers to a definition (possibly itself) if a variable that the second binds occurs in the first. Every definition that lies on a cycle of this relation is a function binding var atpat1 ⋯ atpatn = exp\var\ \atpat_1\ \cdots\ \atpat_n\ \kw{=}\ \expm with n≥1n \geq 1; in particular, no destructuring binding and no definition var = exp\var\ \kw{=}\ \expm without parameters lies on a cycle, even when exp\expm is a lambda expression. The corresponding restriction for top-level declarations is given in Chapter 3.

    core-let-recursion

There is no limit on the size of a phrase: the number of parameters, components, fields or constructors is unbounded, and the limits of an implementation are listed in Appendix E.

Discussions

Discuss this chapter·Search the discussions on GitHub

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