2015 lines · 78.5 KB · TeX
RawDownload
% mosmlref.tex v. 2.00.0 Copyright (C) Peter Sestoft 1994, 2000-06-28%% You may edit for lay-out, or leave out irrelevant sections (if% such omissions are marked somehow), but you may not redistribute the% sources.  The authors' names and the Moscow ML URL must be left in place. \documentclass[fleqn,a4paper]{article} \def\allttcdots{\ensuremath{\cdots}} % this is a hack to get the bullets to hyperlink to a comment: there must be a simpler way\newcounter{extension}\renewcommand{\theextension}{$\bullet$}\newcommand{\x}[1][]{\ref{extension}{#1}} %\newcommand{\x}[1][]{\ref{extension}{\bf{*}#1}} \nonstopmode\usepackage{alltt} \usepackage{isolatin1,mosml,pslatex}\usepackage[T1]{fontenc}\usepackage{geometry} % \documentstyle[A4,fleqn,notesart]{article} \newcommand{\la}{$\langle$}\newcommand{\ra}{$\rangle$}\newcommand{\opop}{\la{\tt op}\ra} \newcommand{\op}{{\tt op}}\newcommand{\longmodid}{{\it longmodid}} % True if running pdflatex\newif\ifpdf\ifx\pdfoutput\undefined    \pdffalse\else    \pdftrue\fi % hyperref should be the *last* package loaded\ifpdf   \pdfcompresslevel=9   % For interactive color output devices (i.e. computer displays):   \usepackage[pdfpagemode=None,colorlinks,urlcolor=blue]{hyperref}\else   % For passive black and white output devices (i.e. printers):   \usepackage{hyperref}\fi \begin{document} \begin{center}   \vspace*{0cm} {\huge\bf Moscow ML Language Overview}\\[0.5cm] {Version 2.00 of June 2000}\\[1cm] Sergei Romanenko, Russian Academy of Sciences, Moscow, Russia\\Claudio Russo, Cambridge University, Cambridge, United Kingdom\\Peter Sestoft, Royal Veterinary and Agricultural University, Copenhagen, Denmark\end{center} \noindent This is a compact reference to the language implemented byMoscow ML, a superset of Standard ML\@.  For reference material onStandard ML, see Milner, Tofte, Harper and MacQueen: {\em The  Definition of Standard ML\/}, The MIT Press 1997.  For a guide tothe practical use of Moscow ML, see the \emph{Moscow ML Owner's  Manual}.  For a detailed description of all Moscow ML librarymodules, see the \emph{Moscow ML Library Documentation}.  % {\bf Acknowledgements:} The present document owes a lot to the {\em%   Definition\/}.Thanks to Don Sannella at LFCS, Division of%   Informatics, University of Edinburgh for funding C. Russo under%   EPSRC grant GR/K63795 . \tableofcontents \vfill \begin{center}\begin{tabular}{|c|}\hline\rule[-0.4cm]{0cm}{1cm}The Moscow ML home page is\ \    \url{http://www.dina.kvl.dk/~sestoft/mosml.html}\\\hline\end{tabular}\end{center} \newpage  \section{Moscow ML's relation to Standard ML}\label{sec-SMLcompliance} Moscow ML implements a proper extension of Standard ML, as  defined in the 1997 {\em Definition of Standard ML\/}.This document describes the language implemented by Moscow ML, not Standard ML \emph{per se}: users seeking an orthodox Standard ML reference should look elsewhere.Having said that, Moscow ML is specifically designed to be backwards compatible with Standard ML. Thus every valid Standard ML program should be a validMoscow ML program, and Moscow ML may be used as if it were simplya Standard ML compiler. Any deviation from this behaviour should be reportedas a bug. % To facilitate the production of code that complies with Standard ML,% both the batch compiler {\tt mosmlc} and the interactive system {\tt%   mosml} accept the command line options {\tt -orthodox}, {\tt%   -conservative} and {\tt -liberal}, which cause the compiler and% interactive system to respectively reject, deprecate with a warning,% or silently accept any Moscow ML specific extensions of Standard ML.% The default compliance level is {\tt -conservative}. In the% interactive system, the compliance level may be set interactively% using the functions {\tt orthodox}, {\tt conservative} and {\tt%   liberal} of type {\tt unit -> unit}. \section{Reserved words}\label{sec-reserved-words} % {\small\begin{verbatim} %       abstype  and  andalso  as  case  do  datatype  else  end  exception  fn  fun  %       handle  if  in  infix  infixr  let  local  nonfix  of  op  open  orelse  raise  rec  %       sig  signature  struct  structure  then  type  val  with  withtype  while  %       (  )  [  ]  {  }  ,  :  :>  ;  ...    _  |  =  =>  ->  #% \end{verbatim}} {\small\begin{alltt} abstype  and  andalso  as  case  do  datatype  else  end eqtype exception  fn  fun  functor handle  if  in  include  infix  infixr  let  local  nonfix  of  op  open  orelse  raise  rec  sharing  sig  signature  struct  structure  then  type  val  where  with  withtype  while  (  )  [  ]  \{  \}  ,  :  :>  ;  ...    _  |  =  =>  ->  #\end{alltt}}  \section{Comments}\label{sec-comments} A comment is any character sequence within comment brackets \verb#(*#and \verb#*)# in which comment brackets are properly nested.  \section{Special constants}\label{sec-special-constants}  \subsubsection*{Integer constants} \begin{quot}\begin{tabular}{@{}lcllllllll}Examples:   & &  \verb#0# & \verb#~0# & \verb#4# & \verb#~04# &\verb#999999# & \verb#0xFFFF# & \verb#~0x1ff#\\Non-examples: & & \verb#0.0# & \verb#~0.0# & \verb#4.0# & \verb#1E0# &\verb#-317# & \verb#0XFFFF# & \verb#-0x1ff#\\\end{tabular}\end{quot}  \subsubsection*{Real constants} \begin{quot}\begin{tabular}{@{}lcllllllll}Examples:   & &  \verb#0.7# & \verb#~0.7# & \verb#3.32E5# & \verb#3E~7# & \verb#~3E~7#  & \verb#3e~7# & \verb#~3e~7#\\Non-examples: & & \verb#23# & \verb#.3# & \verb#4.E5# & \verb#1E2.0# &   \verb#1E+7# & \verb#1E-7#\end{tabular}\end{quot}  \subsubsection*{Word constants} \begin{quot}\begin{tabular}{@{}lcllllllll}Examples:   & &  \verb#0w0# & \verb#0w4# & \verb#0w999999# &\verb#0wxFFFF#  & \verb#0wx1ff#\\Non-examples: & & \verb#0w0.0# & \verb#~0w4# & \verb#-0w4# & \verb#0w1E0# &\verb#0wXFFFF# & \verb#0WxFFFF#\\\end{tabular}\end{quot}  \subsubsection*{String constants} A string constant is a sequence, between quotes (\verb#"#), of zero ormore printable characters, spaces, or escape sequences.  An escapesequence starts with the escape character \verb#\# and stands for acharacter sequence: \begin{quot}\begin{tabular}{@{}lp{5in}}  \verb#\a# & A single character interpreted by the system as  alert (BEL, ASCII 7). \\    \verb#\b# & Backspace (BS, ASCII 8).\\    \verb#\t# & Horisontal tab (HT, ASCII 9).\\    \verb#\n# & Linefeed, also known as newline (LF, ASCII 10). \\    \verb#\v# & Vertical tab (VT, ASCII 11).\\    \verb#\f# & Form feed (FF, ASCII 12).\\   \verb#\r# & Carriage return (CR, ASCII 13).\\    \verb#\^#{\it c\/} & The control character {\it c\/}, where {\it    c\/} may be any character with ASCII code 64--95 (\verb#@# to  \verb#_#).  The ASCII code of \verb#\^#{\it c\/} is 64 less than  that of {\it c\/}.\\    \verb#\#{\it ddd\/} & The character with code {\it ddd\/} (3 decimal  digits denoting an integer 0--255).\\    \verb#\u#{\it xxxx\/} & The character with code {\it xxxx\/} (4 hexadecimal  digits denoting an integer 0--255).\\  \verb#\"# & The double-quote character ({\tt "})\\ \verb#\\# & The backslash character (\verb#\#)\\ \verb#\#$f\cdot\cdot f$\verb#\# & This sequence is ignored, where$f\cdot\cdot f$ stands for a sequence of one or more formattingcharacters (such as space, tab, newline, form-feed).\end{tabular}\end{quot}  \subsubsection*{Character constants} A character constant consists of the symbol \verb$#$ immediatelyfollowed by a string constant of length one. \begin{quot}\begin{tabular}{@{}lclllll}Examples:   & &  \verb$#"a"    $ & \verb$#"\n"   $ & \verb$#"\^Z"  $ &\verb$#"\255" $ & \verb$#"\""$\\Non-examples: & & \verb$# "a"$ & \verb$#c$ & \verb$#"""$ \end{tabular}\end{quot} %\newpage \section{Identifiers}\label{sec-identifiers} \begin{itemize}\item {\bf alphanumeric:} a sequence of letters, digits, primes  (\verb#'#) and underbars (\verb#_#) starting with a letter or prime; \item {\bf symbolic:} any non-empty sequence of the following symbols:\\\verb;      ! % & $ # + - / : < = > ? @ \ ~ ` ^ | *;\end{itemize} \noindent Reserved words (Section~\ref{sec-reserved-words}) areexcluded.  This means that for example \verb$#$ and \verb#|# are notidentifiers, but \verb$##$ and \verb#|=|# are identifiers.  There areseveral classes of identifiers: {\begin{center}\begin{tabular}{@{}lll}{\it vid }  &  (value identifiers)           &    long\\{\it tyvar} &  (type variables)\\{\it tycon} &  (type constructors)         &    long\\{\it lab}   &  (record labels)\\{\it strid} &  (structure identifiers)         &    long\\{\it funid} &  (functor identifiers)         &    long\\{\it modid} &  (module identifiers)         &    long\\{\it sigid} &  (signature identifiers)\\{\it unitid} &  (unit identifiers)\end{tabular}\end{center}}  \begin{itemize}\item A type variable \verb#'a# is an alphanumeric identifier starting  with a prime. %\item An equality type variable \verb#''a# starts with two or more primes.%%\item An imperative type variable \verb#'_a# starts with one or two primes%  followed by an underbar.%%\item An applicative type variable is one which is not imperative. \item A label lab is an identifier, or a positive integral numeral  \verb#1 2 3 #\ldots\ not starting with \verb#0#.   \item For each identifier class X marked `long' above there is a class  longX of long identifiers, which may have a qualifier consisting of  a long structure identifier followed by a dot `\texttt{.}' :  \begin{center}      \begin{tabular}{llll}    {\it longx\/} & ::= &  {\it x\/}         & identifier\\          &     &  {\it longstrid\/}\texttt{.}{\it x\/}  & qualified identifier  \end{tabular}  \end{center} \item  Although structure and functor identifiers reside in separate name-spaces, the syntax of structure and functor identifiers is identical. The set of identifiers {\it modid} ranges over the union of {\it strid} and {\it funid}; {\it longmodid} ranges over the union  of {\it longstrid} and {\it longfunid}. Moscow ML uses type information to resolve each occurrence of a  {\it modid} or {\it longmodid}  to a structure or functor identifier during type checking, using the optional keyword \op\ to resolve any remaining ambiguities. See the comments at the end of Section \ref{sec-modules}. \item Any occurrence of a structure identifier {\it strid\/} that is  not bound in the current context refers to the unit implementation  {\tt unitid.uo\/} of the same name (ie. {\tt unitid} = {\it strid}).  At compile time, the unit's compiled interface {\tt unitid.ui\/}  must exist and have been compiled in \emph{structure} mode.  At link  time, the unit's compiled implementation {\tt unitid.uo\/} must  exist and have been compiled in \emph{structure} mode. \item Any occurrence of a signature identifier {\it sigid\/} that is notbound in the current context refers to the compiled unit interface{\tt unitid.ui\/} of the same name (ie. {\tt unitid} = {\it sigid}).The file {\tt unitid.ui\/} must have been compiled in \emph{structure}mode from an explicit interface {\tt unitid.sig}. \end{itemize} \newpage\section{Infixed operators}\label{sec-infixed-operators} An identifier may be given infix status by the {\tt infix} or {\tt  infixr} directive, which may occur as a declaration or specification.  If identifier{\it id\/} has infix status, then {\it exp\/}$_1$ {\it id\/} {\it  exp\/}$_2$ may occur, in parentheses if necessary, wherever theapplication {\it id\/}\verb#(#{\it exp\/}\et\verb#,# {\it  exp\/}\to\verb#)# or {\it id\/}\verb#{1=#{\it    exp\/}\et\verb#,2=#{\it exp\/}\to\verb#}# would otherwise occur.Infix identifiers in patterns are analogous.  On the other hand, anoccurrence of a qualified identifier, or any identifier prefixed by{\tt op}, is treated as non-infixed.  The form of the fixity directivesis as follows ($n\geq 1$):        \begin{center}\begin{tabular}{@{}llll}{\tt infix}  & $\langle d\rangle$ & $id_1 \cdots id_n$ & left associative\\{\tt infixr} & $\langle d\rangle$ & $id_1 \cdots id_n$ & right associative\\{\tt nonfix} & & $id_1 \cdots id_n$ & non-associative\end{tabular}\end{center} \noindent where $\langle d\rangle$ is an optional decimal digit $d$indicating binding precedence.  A higher value of $d$ indicatestighter binding; the default is \verb#0#.  Fixity directives aresubject to the usual scope rules governing visibility of identifiersdeclared inside {\tt let} and {\tt local}. Fixity directives occurring within {\it dec} in a structure expression {\tt struct {\it dec\/} end} are local to {\it dec}.Fixity directives occurring within {\it spec} in a signature {\tt sig {\it spec\/} end} are local to {\it spec}. Mixed left-associative operators of the same precedence associate tothe left, mixed right-associative operators of the same precedenceassociate to the right, and it is illegal to mix left- andright-associative operators of the same precedence. \section{Notational conventions used in the grammar} \begin{itemize}\item Each syntax class is defined by a list of alternatives, one  alternative on each line.  An empty phrase is represented by an  empty line. \item The brackets \la\ and \ra\ enclose optional phrases. %\newpage\item For any syntax class X (over which {\it x\/} ranges) we define the syntax  class Xseq (over which {\it xseq\/} ranges) as follows:   \begin{center}    \begin{tabular}{llll}      {\it xseq\/} &  ::=  & {\it x\/} & (singleton sequence)\\             &       &           & (empty sequence)\\             &       & {\tt ($x_1$, $\cdots$ , $x_n$)} & (sequence,             $n\geq 1$)    \end{tabular}  \end{center}\item Alternative phrases are listed in order of decreasing precedence. \item L and R indicate left and right association. \item The syntax of types binds more tightly than that of expressions. \item Each iterated construct (e.g.\ {\it match\/}) extends as far to  the right as possible.  Hence a {\tt case} inside a {\tt case}, {\tt    fn}, or {\tt fun} may have to be enclosed in parentheses. \item Moscow ML phrases that are non-compliant       extensions of Standard ML syntax are      marked with an bullet (\x) in the margin.          \item Moscow ML phrases that are non-compliant generalisations of      Standard ML syntax, but have instances that comply with Standard      ML, are marked with an an bullet and a number (\x[$N$]) in the      margin, where $N$ refers to an explanatory comment that appears      in Section \ref{sec-SMLrestrictions}.\end{itemize} \newpage \section{Grammar for the Moscow ML Core language}\label{sec-grammar-core} \subsubsection*{Expressions and Matches} \begin{tabular}{@{}lllll}{\it exp\/} & ::= & {\it infexp\/}\\& & {\tt {\it exp\/} :\ {\it ty\/}} & type constraint (L)\\& & {\tt {\it exp\/}\et\ andalso {\it exp\/}\to} & sequential conjunction\\& & {\tt {\it exp\/}\et\ orelse {\it exp\/}\to}  & sequential disjunction\\& & {\tt {\it exp\/} handle {\it match\/}} & handle exception\\& & {\tt raise {\it exp\/}} & raise exception\\& & {\tt if {\it exp\/}\et\ then {\it exp\/}\to\ else {\it exp\/}\tre}& conditional\\& & {\tt while {\it exp\/}\et\ do {\it exp\/}\to} & iteration\\& & {\tt case {\it exp\/} of {\it match\/}} & case analysis\\& & {\tt fn {\it match\/}} & function expression\\[2ex] {\it infexp\/} & ::= & {\it appexp\/}\\& & {\it infexp\/}\et\ {\it id\/} {\it infexp\/}\to & infixedapplication\\[2ex] {\it appexp\/} & ::= & {\it atexp\/}\\& & {\it appexp\/} {\it atexp\/} & application\\[2ex] {\it atexp\/} & ::= & {\it scon\/} &  special constant (see Section~\ref{sec-special-constants})\\& & \la{\tt op}\ra\ {\it longvid\/} & value identifier\\& & \verb#{# \la\ {\it exprow\/} \ra\ \verb#}# & record\\& & \verb$#$ {\it lab\/} & record selector\\& & \verb#()# &           0-tuple\\& & {\tt ({\it exp\/}\et, $\cdots$ , {\it exp\/}\n)} & $n$-tuple, $n\geq 2$\\& & {\tt [{\it exp\/}\et, $\cdots$ , {\it exp\/}\n]} & list, $n\geq 0$\\& & {\tt \#[{\it exp\/}\et, $\cdots$ , {\it exp\/}\n]} & vector, $n\geq 0$\\& & {\tt ({\it exp\/}\et; $\cdots$ ; {\it exp\/}\n)} & sequence, $n\geq 2$\\& & {\tt let {\it dec\/} in {\it exp\/}\et; $\cdots$ ; {\it exp\/}\n\  end} & local declaration, $n\geq 1$\\& & {\tt [ structure {\it modexp\/} as {\it sigexp\/} ]} & structure package & \x \\& & {\tt [ functor {\it modexp\/} as {\it sigexp\/} ]} & functor package & \x \\& & {\tt  ( {\it exp\/} ) }\\[2ex] {\it exprow\/} & ::= & {\tt {\it lab\/} = {\it exp\/} \la\ , {\it    exprow\/} \ra} & expression row\\[2ex] {\it match\/} & ::= & {\tt {\it mrule\/} \la\ | {\it match\/} \ra}\\[2ex] {\it mrule\/} & ::= & {\tt {\it pat\/} => {\it exp\/}}\end{tabular}  \subsubsection*{Declarations and Bindings} \begin{tabular}{@{}lllll}{\it dec\/} & ::= & {\tt val {\it tyvarseq\/} {\it valbind\/}} & value declaration\\& & {\tt fun {\it tyvarseq\/} {\it fvalbind\/}} & function declaration\\& & {\tt type {\it typbind\/}} & type declaration\\& & {\tt datatype {\it datbind\/} \la\ withtype {\it typbind\/} \ra} & datatype declaration\\& & {\tt datatype {\it tycon\/} = datatype {\it tyconpath\/}}& datatype replication\\& & {\tt abstype {\it datbind\/} \la\ withtype {\it typbind\/} \ra}& abstype declaration\\& & \hspace{1.5cm}{\tt with {\it dec\/} end}\\& & {\tt exception {\it exbind\/}} & exception declaration\\& & {\tt local {\it dec\/}\et\ in {\it dec\/}\to\ end} & local declaration\\& & {\tt open {\it longstrid\/}\et\ $\cdots$ {\it longstrid\/}\n}& open declaration, $n\geq 1$\\& & {\tt structure {\it strbind}}& structure declaration & \x[\ref{strdec}]\\& & {\tt functor {\it funbind}}& functor declaration & \x[\ref{topdec}]\\& & {\tt signature {\it sigbind}}& signature declaration & \x[\ref{topdec}]\\& & & empty declaration\\& & {\tt {\it dec\/}\et\ \la;\ra\ {\it dec\/}\to} & sequential declaration\\& & {\tt infix \la{\it d\/}\ra\ $id_1 \cdots id_n$} & infix (left)  directive, $n\geq 1$\\& & {\tt infixr \la{\it d\/}\ra\ $id_1 \cdots id_n$} & infix (right)  directive, $n\geq 1$\\& & {\tt nonfix $id_1 \cdots id_n$} & nonfix directive, $n\geq  1$\\[2ex] {\it valbind\/} & ::= & {\tt {\it pat\/} = {\it exp\/} \la\ and {\it    valbind\/} \ra} & value binding\\& & {\tt rec {\it valbind\/}} & recursive binding\\[2ex] 

Lines 1–500 of 2015.