adamc@524: \documentclass{article} adamc@524: \usepackage{fullpage,amsmath,amssymb,proof} adamc@524: adamc@524: \newcommand{\cd}[1]{\texttt{#1}} adamc@524: \newcommand{\mt}[1]{\mathsf{#1}} adamc@524: adamc@524: \newcommand{\rc}{+ \hspace{-.075in} + \;} adamc@524: adamc@524: \begin{document} adamc@524: adamc@524: \title{The Ur/Web Manual} adamc@524: \author{Adam Chlipala} adamc@524: adamc@524: \maketitle adamc@524: adamc@524: \section{Syntax} adamc@524: adamc@524: \subsection{Lexical Conventions} adamc@524: adamc@524: We give the Ur language definition in \LaTeX $\;$ math mode, since that is prettier than monospaced ASCII. The corresponding ASCII syntax can be read off directly. Here is the key for mapping math symbols to ASCII character sequences. adamc@524: adamc@524: \begin{center} adamc@524: \begin{tabular}{rl} adamc@524: \textbf{\LaTeX} & \textbf{ASCII} \\ adamc@524: $\to$ & \cd{->} \\ adamc@524: $\times$ & \cd{*} \\ adamc@524: $\lambda$ & \cd{fn} \\ adamc@524: $\Rightarrow$ & \cd{=>} \\ adamc@524: $\rc$ & \cd{++} \\ adamc@524: \\ adamc@524: $x$ & Normal textual identifier, not beginning with an uppercase letter \\ adamc@525: $X$ & Normal textual identifier, beginning with an uppercase letter \\ adamc@524: \end{tabular} adamc@524: \end{center} adamc@524: adamc@525: 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. adamc@524: adamc@526: 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. adamc@526: adamc@524: \subsection{Core Syntax} adamc@524: adamc@524: \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. adamc@524: $$\begin{array}{rrcll} adamc@524: \textrm{Kinds} & \kappa &::=& \mt{Type} & \textrm{proper types} \\ adamc@525: &&& \mt{Unit} & \textrm{the trivial constructor} \\ adamc@525: &&& \mt{Name} & \textrm{field names} \\ adamc@525: &&& \kappa \to \kappa & \textrm{type-level functions} \\ adamc@525: &&& \{\kappa\} & \textrm{type-level records} \\ adamc@525: &&& (\kappa\times^+) & \textrm{type-level tuples} \\ adamc@525: &&& (\kappa) & \textrm{explicit precedence} \\ adamc@524: \end{array}$$ adamc@524: adamc@524: Ur supports several different notions of functions that take types as arguments. These arguments can be either implicit, causing them to be inferred at use sites; or explicit, forcing them to be specified manually at use sites. There is a common explicitness annotation convention applied at the definitions of and in the types of such functions. adamc@524: $$\begin{array}{rrcll} adamc@524: \textrm{Explicitness} & ? &::=& :: & \textrm{explicit} \\ adamc@525: &&& \; ::: & \textrm{implicit} adamc@524: \end{array}$$ adamc@524: adamc@524: \emph{Constructors} are the main class of compile-time-only data. They include proper types and are classified by kinds. adamc@524: $$\begin{array}{rrcll} adamc@524: \textrm{Constructors} & c, \tau &::=& (c) :: \kappa & \textrm{kind annotation} \\ adamc@525: &&& x & \textrm{constructor variable} \\ adamc@524: \\ adamc@525: &&& \tau \to \tau & \textrm{function type} \\ adamc@525: &&& x \; ? \; \kappa \to \tau & \textrm{polymorphic function type} \\ adamc@525: &&& \$ c & \textrm{record type} \\ adamc@524: \\ adamc@525: &&& c \; c & \textrm{type-level function application} \\ adamc@525: &&& \lambda x \; ? \; \kappa \Rightarrow c & \textrm{type-level function abstraction} \\ adamc@524: \\ adamc@525: &&& () & \textrm{type-level unit} \\ adamc@525: &&& \#X & \textrm{field name} \\ adamc@524: \\ adamc@525: &&& [(c = c)^*] & \textrm{known-length type-level record} \\ adamc@525: &&& c \rc c & \textrm{type-level record concatenation} \\ adamc@525: &&& \mt{fold} & \textrm{type-level record fold} \\ adamc@524: \\ adamc@525: &&& (c^+) & \textrm{type-level tuple} \\ adamc@525: &&& c.n & \textrm{type-level tuple projection ($n \in \mathbb N^+$)} \\ adamc@524: \\ adamc@525: &&& \lambda [c \sim c] \Rightarrow c & \textrm{guarded constructor} \\ adamc@524: \\ adamc@525: &&& (c) & \textrm{explicit precedence} \\ adamc@525: \end{array}$$ adamc@525: adamc@525: Modules of the module system are described by \emph{signatures}. adamc@525: $$\begin{array}{rrcll} adamc@525: \textrm{Signatures} & S &::=& \mt{sig} \; s^* \; \mt{end} & \textrm{constant} \\ adamc@525: &&& X & \textrm{variable} \\ adamc@525: &&& \mt{functor}(X : S) : S & \textrm{functor} \\ adamc@525: &&& S \; \mt{where} \; x = c & \textrm{concretizing an abstract constructor} \\ adamc@525: &&& M.X & \textrm{projection from a module} \\ adamc@525: \\ adamc@525: \textrm{Signature items} & s &::=& \mt{con} \; x :: \kappa & \textrm{abstract constructor} \\ adamc@525: &&& \mt{con} \; x :: \kappa = c & \textrm{concrete constructor} \\ adamc@525: &&& \mt{datatype} \; x \; x^* = dc\mid^+ & \textrm{algebraic datatype declaration} \\ adamc@525: &&& \mt{datatype} \; x = M.x & \textrm{algebraic datatype import} \\ adamc@525: &&& \mt{val} \; x : \tau & \textrm{value} \\ adamc@525: &&& \mt{structure} \; X : S & \textrm{sub-module} \\ adamc@525: &&& \mt{signature} \; X = S & \textrm{sub-signature} \\ adamc@525: &&& \mt{include} \; S & \textrm{signature inclusion} \\ adamc@525: &&& \mt{constraint} \; c \sim c & \textrm{record disjointness constraint} \\ adamc@525: &&& \mt{class} \; x & \textrm{abstract type class} \\ adamc@525: &&& \mt{class} \; x = c & \textrm{concrete type class} \\ adamc@525: \\ adamc@525: \textrm{Datatype constructors} & dc &::=& X & \textrm{nullary constructor} \\ adamc@525: &&& X \; \mt{of} \; \tau & \textrm{unary constructor} \\ adamc@524: \end{array}$$ adamc@524: adamc@526: \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. adamc@526: $$\begin{array}{rrcll} adamc@526: \textrm{Patterns} & p &::=& \_ & \textrm{wildcard} \\ adamc@526: &&& x & \textrm{variable} \\ adamc@526: &&& \ell & \textrm{constant} \\ adamc@526: &&& \hat{X} & \textrm{nullary constructor} \\ adamc@526: &&& \hat{X} \; p & \textrm{unary constructor} \\ adamc@526: &&& \{(x = p,)^*\} & \textrm{rigid record pattern} \\ adamc@526: &&& \{(x = p,)^+, \ldots\} & \textrm{flexible record pattern} \\ adamc@526: \\ adamc@526: \textrm{Qualified capitalized variable} & \hat{X} &::=& X & \textrm{not from a module} \\ adamc@526: &&& M.X & \textrm{projection from a module} \\ adamc@526: \end{array}$$ adamc@526: adamc@524: \end{document}