comparison doc/manual.tex @ 526:f87fd1549c33

Patterns
author Adam Chlipala <adamc@hcoop.net>
date Thu, 27 Nov 2008 15:06:29 -0500
parents 602f7536cae3
children 74dd4dca9e32
comparison
equal deleted inserted replaced
525:602f7536cae3 526:f87fd1549c33
32 $X$ & Normal textual identifier, beginning with an uppercase letter \\ 32 $X$ & Normal textual identifier, beginning with an uppercase letter \\
33 \end{tabular} 33 \end{tabular}
34 \end{center} 34 \end{center}
35 35
36 We often write syntax like $e^*$ to indicate zero or more copies of $e$, $e^+$ to indicate one or more copies, and $e,^*$ and $e,^+$ to indicate multiple copies separated by commas. Another separator may be used in place of a comma. The $e$ term may be surrounded by parentheses to indicate grouping; those parentheses should not be included in the actual ASCII. 36 We often write syntax like $e^*$ to indicate zero or more copies of $e$, $e^+$ to indicate one or more copies, and $e,^*$ and $e,^+$ to indicate multiple copies separated by commas. Another separator may be used in place of a comma. The $e$ term may be surrounded by parentheses to indicate grouping; those parentheses should not be included in the actual ASCII.
37
38 We write $\ell$ for literals of the primitive types, for the most part following C conventions. There are $\mt{int}$, $\mt{float}$, and $\mt{string}$ literals.
37 39
38 \subsection{Core Syntax} 40 \subsection{Core Syntax}
39 41
40 \emph{Kinds} classify types and other compile-time-only entities. Each kind in the grammar is listed with a description of the sort of data it classifies. 42 \emph{Kinds} classify types and other compile-time-only entities. Each kind in the grammar is listed with a description of the sort of data it classifies.
41 $$\begin{array}{rrcll} 43 $$\begin{array}{rrcll}
103 \\ 105 \\
104 \textrm{Datatype constructors} & dc &::=& X & \textrm{nullary constructor} \\ 106 \textrm{Datatype constructors} & dc &::=& X & \textrm{nullary constructor} \\
105 &&& X \; \mt{of} \; \tau & \textrm{unary constructor} \\ 107 &&& X \; \mt{of} \; \tau & \textrm{unary constructor} \\
106 \end{array}$$ 108 \end{array}$$
107 109
110 \emph{Patterns} are used to describe structural conditions on expressions, such that expressions may be tested against patterns, generating assignments to pattern variables if successful.
111 $$\begin{array}{rrcll}
112 \textrm{Patterns} & p &::=& \_ & \textrm{wildcard} \\
113 &&& x & \textrm{variable} \\
114 &&& \ell & \textrm{constant} \\
115 &&& \hat{X} & \textrm{nullary constructor} \\
116 &&& \hat{X} \; p & \textrm{unary constructor} \\
117 &&& \{(x = p,)^*\} & \textrm{rigid record pattern} \\
118 &&& \{(x = p,)^+, \ldots\} & \textrm{flexible record pattern} \\
119 \\
120 \textrm{Qualified capitalized variable} & \hat{X} &::=& X & \textrm{not from a module} \\
121 &&& M.X & \textrm{projection from a module} \\
122 \end{array}$$
123
108 \end{document} 124 \end{document}