V10/cmd/sml/doc/refman/standard.tex

\chapter{Standard bindings}
ML provides the record type constructor 
$ \verb"{" {\bf lab}_1 \verb":" {\bf ty}_1 , \underline{\ \ \ }
 , {\bf lab}_n \verb":" {\bf ty}_n \verb"}"$ for any set 
$\{ {\bf lab}_i \} $ of labels and corresponding set 
$\{ {\bf ty}_i \} $ of types.  The language also provides the infixed
function-type constructor \verb"->".  Otherwise, type constructors
are postfixed.  The following are standard:

\begin{description}
\item[Type {\em constants} (nullary constructors):]  unit, bool, exn, int,
real, string, instream, outstream
\item[Unary type constructors:]  list, ref
\end{description}

The constructors unit, bool, and list are fully defined by the
following assumed declaration
\begin{verbatim}
infixr 5 ::
type unit = {}
datatype    bool = true | false
datatype  'a list = nil |  :: of {1 : 'a, 2 : 'a list}
\end{verbatim}

The word ``unit'' is chosen since the type contains just one value
``\verb"{}"'', the empty record.  This is why it is preferred to the
word ``void'' of Algol-68.

The type constants \verb"int", \verb"real", and \verb"string"
are equipped with special
constants as described in section 2.3.  The type constructor
\verb"ref" is for constructing reference types; see
Chapter~\ref{reference}.
The type constant \verb"exn" is the type of all exceptions, and
is a datatype containing an unbounded number of constructors
generated by \verb"exception" bindings (see Chapter~\ref{exception}).



The initial top-level environment is comprised of a set of standard
bindings.  The initial environment is much more extensive than the
environment described in {\it The Definition of Standard ML}, and
is almost a proper superset.  The differences are:

\begin{itemize}
\item All values, types, datatypes, etc. are grouped into structures;
these structures are opened in the initial environment so that the
names can be used without a structure-name qualification.

\item There are many additional initial bindings, described in 
Appendix~\ref{library}.

\item The functions \verb"input" and \verb"output" are curried in Standard
ML of New Jersey, e.g. \verb"input: instream->int->string" instead of
\verb"input: instream*int->string".

\item The integer functions \verb"+", \verb"-", \verb"div", \verb"mod", 
\verb"*", \verb"~", \verb"abs" all raise \verb"Overflow" if the result is out-of-range,
rather than \verb"Sum", \verb"Diff", \verb"Div", \verb"Mod", \verb"Prod",
\verb"Neg", \verb"Abs", respectively.

\item The integer \verb"div" function rounds toward zero, and \verb"x mod y"
is defined as \verb"x-y*(x div y)".

\end{itemize}

Standard ML of New Jersey is distributed with a structure \verb"Standard"
that may be loaded into the initial environment to simulate
environment described in the {\it Definition}.