\chapter{The standard library} \label{c:stdlib}\cutname{stdlib.html}
\pdfchapterfold{-32}{The standard library}

This chapter describes the functions provided by the OCaml
standard library. The modules from the standard library are
automatically linked with the user's object code files by the "ocamlc"
command. Hence, these modules can be used in standalone programs without
having to add any ".cmo" file on the command line for the linking
phase. Similarly, in interactive use, these globals can be used in
toplevel phrases without having to load any ".cmo" file in memory.

Unlike the "Pervasives" module from the core library, the modules from the
standard library are not automatically ``opened'' when a compilation
starts, or when the toplevel system is launched. Hence it is necessary
to use qualified identifiers to refer to the functions provided by these
modules, or to add "open" directives.

\label{stdlib:top}

\section*{Conventions}

For easy reference, the modules are listed below in alphabetical order
of module names.
For each module, the declarations from its signature are printed
one by one in typewriter font, followed by a short comment.
All modules and the identifiers they export are indexed at the end of
this report.

\begin{latexonly}
\section*{Overview}

Here is a short listing, by theme, of the standard library modules.

\subsubsection*{Data structures:}
\begin{tabular}{lll}
% Beware: these entries must be written in a very rigidly-defined
% format, or the check-stdlib-modules script will complain.
"String" & p.~\pageref{String} & string operations \\
"Bytes" & p.~\pageref{Bytes} & operations on byte sequences\\
"Array" & p.~\pageref{Array} & array operations \\
"List" & p.~\pageref{List} & list operations \\
"StdLabels" & p.~\pageref{StdLabels} & labelized versions of
the above 4 modules \\
"Char" & p.~\pageref{Char} & character operations \\
"Uchar" & p.~\pageref{Uchar} & Unicode characters \\
"Sort" & p.~\pageref{Sort} & (deprecated) \\
"Hashtbl" & p.~\pageref{Hashtbl} & hash tables and hash functions \\
"Random" & p.~\pageref{Random} & pseudo-random number generator \\
"Set" & p.~\pageref{Set} & sets over ordered types \\
"Map" & p.~\pageref{Map} & association tables over ordered types \\
"MoreLabels" & p.~\pageref{MoreLabels} & labelized versions of
"Hashtbl", "Set", and "Map" \\
"Oo" & p.~\pageref{Oo} & useful functions on objects \\
"Stack" & p.~\pageref{Stack} & last-in first-out stacks \\
"Queue" & p.~\pageref{Queue} & first-in first-out queues \\
"Buffer" & p.~\pageref{Buffer} & buffers that grow on demand \\
"Lazy" & p.~\pageref{Lazy} & delayed evaluation \\
"Weak" & p.~\pageref{Weak} & references that don't prevent objects
from being garbage-collected \\
"Ephemeron" & p.~\pageref{Ephemeron} & ephemerons and weak hash tables
\end{tabular}
\subsubsection*{Arithmetic:}
\begin{tabular}{lll}
"Complex" & p.~\pageref{Complex} & Complex numbers \\
"Int32" & p.~\pageref{Int32} & operations on 32-bit integers \\
"Int64" & p.~\pageref{Int64} & operations on 64-bit integers \\
"Nativeint" & p.~\pageref{Nativeint} & operations on platform-native
integers
\end{tabular}
\subsubsection{Input/output:}
\begin{tabular}{lll}
"Format" & p.~\pageref{Format} & pretty printing with automatic
indentation and line breaking \\
"Marshal" & p.~\pageref{Marshal} & marshaling of data structures \\
"Printf" & p.~\pageref{Printf} & formatting printing functions \\
"Scanf" & p.~\pageref{Scanf} & formatted input functions \\
"Digest" & p.~\pageref{Digest} & MD5 message digest \\
\end{tabular}
\subsubsection{Parsing:}
\begin{tabular}{lll}
"Genlex" & p.~\pageref{Genlex} & a generic lexer over streams \\
"Lexing" & p.~\pageref{Lexing} & the run-time library for lexers generated by "ocamllex" \\
"Parsing" & p.~\pageref{Parsing} & the run-time library for parsers generated by "ocamlyacc" \\
"Stream" & p.~\pageref{Stream} & basic functions over streams \\
\end{tabular}
\subsubsection{System interface:}
\begin{tabular}{lll}
"Arg" & p.~\pageref{Arg} & parsing of command line arguments \\
"Callback" & p.~\pageref{Callback} & registering OCaml functions to
be called from C \\
"Filename" & p.~\pageref{Filename} & operations on file names \\
"Gc" & p.~\pageref{Gc} & memory management control and statistics \\
"Printexc" & p.~\pageref{Printexc} & a catch-all exception handler \\
"Spacetime" & p.~\pageref{Spacetime} & memory profiler \\
"Sys" & p.~\pageref{Sys} & system interface \\
\end{tabular}
\end{latexonly}

\ifouthtml
\begin{links}
\item \ahref{libref/Arg.html}{Module \texttt{Arg}: parsing of command line arguments}
\item \ahref{libref/Array.html}{Module \texttt{Array}: array operations}
\item \ahref{libref/ArrayLabels.html}{Module \texttt{ArrayLabels}: array operations (with labels)}
\item \ahref{libref/Buffer.html}{Module \texttt{Buffer}: extensible buffers}
\item \ahref{libref/Bytes.html}{Module \texttt{Bytes}: byte sequences}
\item \ahref{libref/BytesLabels.html}{Module \texttt{BytesLabels}: byte sequences (with labels)}
\item \ahref{libref/Callback.html}{Module \texttt{Callback}: registering OCaml values with the C runtime}
\item \ahref{libref/Char.html}{Module \texttt{Char}: character operations}
\item \ahref{libref/Complex.html}{Module \texttt{Complex}: Complex numbers}
\item \ahref{libref/Digest.html}{Module \texttt{Digest}: MD5 message digest}
\item \ahref{libref/Ephemeron.html}{Module \texttt{Ephemeron}: Ephemerons and weak hash table}
\item \ahref{libref/Filename.html}{Module \texttt{Filename}: operations on file names}
\item \ahref{libref/Format.html}{Module \texttt{Format}: pretty printing}
\item \ahref{libref/Gc.html}{Module \texttt{Gc}: memory management control and statistics; finalized values}
\item \ahref{libref/Genlex.html}{Module \texttt{Genlex}: a generic lexical analyzer}
\item \ahref{libref/Hashtbl.html}{Module \texttt{Hashtbl}: hash tables and hash functions}
\item \ahref{libref/Int32.html}{Module \texttt{Int32}: 32-bit integers}
\item \ahref{libref/Int64.html}{Module \texttt{Int64}: 64-bit integers}
\item \ahref{libref/Lazy.html}{Module \texttt{Lazy}: deferred computations}
\item \ahref{libref/Lexing.html}{Module \texttt{Lexing}: the run-time library for lexers generated by \texttt{ocamllex}}
\item \ahref{libref/List.html}{Module \texttt{List}: list operations}
\item \ahref{libref/ListLabels.html}{Module \texttt{ListLabels}: list operations (with labels)}
\item \ahref{libref/Map.html}{Module \texttt{Map}: association tables over ordered types}
\item \ahref{libref/Marshal.html}{Module \texttt{Marshal}: marshaling of data structures}
\item \ahref{libref/MoreLabels.html}{Module \texttt{MoreLabels}: Include modules \texttt{Hashtbl}, \texttt{Map} and \texttt{Set} with labels}
\item \ahref{libref/Nativeint.html}{Module \texttt{Nativeint}: processor-native integers}
\item \ahref{libref/Oo.html}{Module \texttt{Oo}: object-oriented extension}
\item \ahref{libref/Parsing.html}{Module \texttt{Parsing}: the run-time library for parsers generated by \texttt{ocamlyacc}}
\item \ahref{libref/Printexc.html}{Module \texttt{Printexc}: facilities for printing exceptions}
\item \ahref{libref/Printf.html}{Module \texttt{Printf}: formatting printing functions}
\item \ahref{libref/Queue.html}{Module \texttt{Queue}: first-in first-out queues}
\item \ahref{libref/Random.html}{Module \texttt{Random}: pseudo-random number generator (PRNG)}
\item \ahref{libref/Scanf.html}{Module \texttt{Scanf}: formatted input functions}
\item \ahref{libref/Set.html}{Module \texttt{Set}: sets over ordered types}
\item \ahref{libref/Sort.html}{Module \texttt{Sort}: deprecated}
\item \ahref{libref/Spacetime.html}{Module \texttt{Spacetime}: memory profiler}
\item \ahref{libref/Stack.html}{Module \texttt{Stack}: last-in first-out stacks}
\item \ahref{libref/StdLabels.html}{Module \texttt{StdLabels}: Include modules \texttt{Array}, \texttt{List} and \texttt{String} with labels}
\item \ahref{libref/Stream.html}{Module \texttt{Stream}: streams and parsers}
\item \ahref{libref/String.html}{Module \texttt{String}: string operations}
\item \ahref{libref/StringLabels.html}{Module \texttt{StringLabels}: string operations (with labels)}
\item \ahref{libref/Sys.html}{Module \texttt{Sys}: system interface}
\item \ahref{libref/Uchar.html}{Module \texttt{Uchar}: Unicode characters}
\item \ahref{libref/Weak.html}{Module \texttt{Weak}: arrays of weak pointers}
\end{links}
\else
\input{Arg.tex}
\input{Array.tex}
\input{ArrayLabels.tex}
\input{Buffer.tex}
\input{Bytes.tex}
\input{BytesLabels.tex}
\input{Callback.tex}
\input{Char.tex}
\input{Complex.tex}
\input{Digest.tex}
\input{Ephemeron.tex}
\input{Filename.tex}
\input{Format.tex}
\input{Gc.tex}
\input{Genlex.tex}
\input{Hashtbl.tex}
\input{Int32.tex}
\input{Int64.tex}
\input{Lazy.tex}
\input{Lexing.tex}
\input{List.tex}
\input{ListLabels.tex}
\input{Map.tex}
\input{Marshal.tex}
\input{MoreLabels.tex}
\input{Nativeint.tex}
\input{Oo.tex}
\input{Parsing.tex}
\input{Printexc.tex}
\input{Printf.tex}
\input{Queue.tex}
\input{Random.tex}
\input{Scanf.tex}
\input{Set.tex}
\input{Sort.tex}
\input{Spacetime.tex}
\input{Stack.tex}
\input{StdLabels.tex}
\input{Stream.tex}
\input{String.tex}
\input{StringLabels.tex}
\input{Sys.tex}
\input{Uchar.tex}
\input{Weak.tex}
\fi
