|
|
1.1 ! root 1: \chapter{Standard bindings} ! 2: ML provides the record type constructor ! 3: $ \verb"{" {\bf lab}_1 \verb":" {\bf ty}_1 , \underline{\ \ \ } ! 4: , {\bf lab}_n \verb":" {\bf ty}_n \verb"}"$ for any set ! 5: $\{ {\bf lab}_i \} $ of labels and corresponding set ! 6: $\{ {\bf ty}_i \} $ of types. The language also provides the infixed ! 7: function-type constructor \verb"->". Otherwise, type constructors ! 8: are postfixed. The following are standard: ! 9: ! 10: \begin{description} ! 11: \item[Type {\em constants} (nullary constructors):] unit, bool, exn, int, ! 12: real, string, instream, outstream ! 13: \item[Unary type constructors:] list, ref ! 14: \end{description} ! 15: ! 16: The constructors unit, bool, and list are fully defined by the ! 17: following assumed declaration ! 18: \begin{verbatim} ! 19: infixr 5 :: ! 20: type unit = {} ! 21: datatype bool = true | false ! 22: datatype 'a list = nil | :: of {1 : 'a, 2 : 'a list} ! 23: \end{verbatim} ! 24: ! 25: The word ``unit'' is chosen since the type contains just one value ! 26: ``\verb"{}"'', the empty record. This is why it is preferred to the ! 27: word ``void'' of Algol-68. ! 28: ! 29: The type constants \verb"int", \verb"real", and \verb"string" ! 30: are equipped with special ! 31: constants as described in section 2.3. The type constructor ! 32: \verb"ref" is for constructing reference types; see ! 33: Chapter~\ref{reference}. ! 34: The type constant \verb"exn" is the type of all exceptions, and ! 35: is a datatype containing an unbounded number of constructors ! 36: generated by \verb"exception" bindings (see Chapter~\ref{exception}). ! 37: ! 38: ! 39: ! 40: The initial top-level environment is comprised of a set of standard ! 41: bindings. The initial environment is much more extensive than the ! 42: environment described in {\it The Definition of Standard ML}, and ! 43: is almost a proper superset. The differences are: ! 44: ! 45: \begin{itemize} ! 46: \item All values, types, datatypes, etc. are grouped into structures; ! 47: these structures are opened in the initial environment so that the ! 48: names can be used without a structure-name qualification. ! 49: ! 50: \item There are many additional initial bindings, described in ! 51: Appendix~\ref{library}. ! 52: ! 53: \item The functions \verb"input" and \verb"output" are curried in Standard ! 54: ML of New Jersey, e.g. \verb"input: instream->int->string" instead of ! 55: \verb"input: instream*int->string". ! 56: ! 57: \item The integer functions \verb"+", \verb"-", \verb"div", \verb"mod", ! 58: \verb"*", \verb"~", \verb"abs" all raise \verb"Overflow" if the result is out-of-range, ! 59: rather than \verb"Sum", \verb"Diff", \verb"Div", \verb"Mod", \verb"Prod", ! 60: \verb"Neg", \verb"Abs", respectively. ! 61: ! 62: \item The integer \verb"div" function rounds toward zero, and \verb"x mod y" ! 63: is defined as \verb"x-y*(x div y)". ! 64: ! 65: \end{itemize} ! 66: ! 67: Standard ML of New Jersey is distributed with a structure \verb"Standard" ! 68: that may be loaded into the initial environment to simulate ! 69: environment described in the {\it Definition}.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.