The syntax of programs is given in Chapter 9. The syntax of long identifiers is that of Chapter 2.
The full grammar of the Core and of Modules consists of the grammar of Chapters 2 and 3, in which each derived form of Appendix A is added as an alternative of the phrase class it belongs to. The grammatical rules are shown in Figures 31, 32, 33, 34 and 35. An alternative whose label carries the mark † is a derived form, whose equivalent form is given in Appendix A; every other alternative is a phrase of the bare language, and has the same label as in Chapter 2 or 3. No subclass of Exp is introduced: which expressions may be the operands of an operator chain is stated in Section 2.7.
The grammatical conventions are those of Chapter 2, namely:
The brackets ⟨⟩ enclose optional phrases.
Alternative forms for each phrase class are in order of decreasing precedence. L (resp. R) means left (resp. right) association.
The infixed application, conjunction and disjunction alternatives are grouped by the fixities of Figure 3, as Section 2.7 describes, and not by their order in Figure 31.
Which item - is a negation symbol, and which . begins a field selection or a field accessor, is decided by lexical analysis (Section 2.5).
The precedence of types and of patterns, and the extent of lambda expressions, case expressions and let expressions, are as stated with the grammar of the Core (Figure 5 and the conventions before it); the extent of each phrase is decided by the layout rule (Sections 2.6 and 3.4).
The separator ; between match rules and between top-level declarations, and the connective and between the members of a value binding or of a custom-type binding, are abstract syntax. Neither is an item of source text: match rules, the definitions of a let and the declarations of a module are separated by layout, and and is not a reserved word. Likewise an annotated binding var:ty=exp is written in source text as the annotation var:ty followed by a definition of var. The derived alternatives letvalbind1⋯valbindninexp and topdec1⋯topdecn are the forms in which several definitions and declarations are written; in them each valbindi is a definition, that is, a value binding without and, and each topdeci is a single declaration, as listed in Section A.2.
The syntactic restrictions are those of Sections 2.10 and 3.7. They apply to phrases of the full grammar, that is, to a program as written, before any derived form is replaced by its equivalent form.
Figure 31: Full Grammar: Expressions, Matches, Declarations and Bindings
In the infixed application alternative, op is neither && nor ||. The alternative -atexp is atomic, so that a negated expression may be the argument of an application.
Type expressions have no derived forms; Figure 33 is Figure 7 unchanged. Modules, headers, imports and exposing lists have no derived forms either: every module has a header, and Figure 34 is Figure 9 unchanged.
module
::=
headerimportstopdec
module
header
::=
modulemodidexposingexplist
plain
portmodulemodidexposingexplist
port module
imports
::=
importmodid⟨asmodid′⟩
import
⟨exposingexplist⟩imports
empty
explist
::=
(..)
everything
(item1,⋯,itemn)
explicit
(n≥1)
item
::=
var
value
(op)
operator
tycon
type
tycon(..)
open type
Figure 34: Full Grammar: Modules, Headers, Imports and Exposing Lists
Figure 35: Full Grammar: Top-level Declarations and Bindings
A top-level value declaration as written is a variable binding or a function binding without and; the function binding alternative of Figure 31 applies to it.