\chapter{The standard library} \label{c:stdlib}\cutname{stdlib.html} 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 core "Stdlib" module, submodules are not automatically ``opened'' when 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} \begin{latexonly} \section*{s:stdlib-conv}{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. \section*{s:stdlib-overview}{Overview} Here is a short listing, by theme, of the standard library modules. \subsubsection*{sss:stdlib-data-structures}{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.~\stdpageref{String} & string operations \\ "Bytes" & p.~\stdpageref{Bytes} & operations on byte sequences\\ "Array" & p.~\stdpageref{Array} & array operations \\ "List" & p.~\stdpageref{List} & list operations \\ "StdLabels" & p.~\stdpageref{StdLabels} & labelized versions of the above 4 modules \\ "Unit" & p.~\stdpageref{Unit} & unit values \\ "Bool" & p.~\stdpageref{Bool} & boolean values \\ "Char" & p.~\stdpageref{Char} & character operations \\ "Uchar" & p.~\stdpageref{Uchar} & Unicode characters \\ "Int" & p.~\stdpageref{Int} & integer values \\ "Option" & p.~\stdpageref{Option} & option values \\ "Pair" & p.~\stdpageref{Pair} & pairs of values \\ "Result" & p.~\stdpageref{Result} & result values \\ "Effect" & p.~\stdpageref{Effect} & effect handlers \\ "Either" & p.~\stdpageref{Either} & either values \\ "Hashtbl" & p.~\stdpageref{Hashtbl} & hash tables and hash functions \\ "Random" & p.~\stdpageref{Random} & pseudo-random number generator \\ "Set" & p.~\stdpageref{Set} & sets over ordered types \\ "Map" & p.~\stdpageref{Map} & association tables over ordered types \\ "MoreLabels" & p.~\stdpageref{MoreLabels} & labelized versions of "Hashtbl", "Set", and "Map" \\ "Oo" & p.~\stdpageref{Oo} & useful functions on objects \\ "Stack" & p.~\stdpageref{Stack} & last-in first-out stacks \\ "Queue" & p.~\stdpageref{Queue} & first-in first-out queues \\ "Pqueue" & p.~\stdpageref{Pqueue} & priority queues \\ "Buffer" & p.~\stdpageref{Buffer} & buffers that grow on demand \\ "Dynarray" & p.~\stdpageref{Dynarray} & dynamic arrays: arrays that grow on demand \\ "Seq" & p.~\stdpageref{Seq} & functional iterators \\ "Lazy" & p.~\stdpageref{Lazy} & delayed evaluation \\ "Weak" & p.~\stdpageref{Weak} & references that don't prevent objects from being garbage-collected \\ "Atomic" & p.~\stdpageref{Atomic} & atomic references (for compatibility with concurrent runtimes) \\ "Ephemeron" & p.~\stdpageref{Ephemeron} & ephemerons and weak hash tables \\ "Bigarray" & p.~\stdpageref{Bigarray} & large, multi-dimensional, numerical arrays \\ "Iarray" & p.~\stdpageref{Iarray} & immutable arrays \end{tabular} \subsubsection*{sss:stdlib-arith}{Arithmetic:} \begin{tabular}{lll} "Complex" & p.~\stdpageref{Complex} & complex numbers \\ "Float" & p.~\stdpageref{Float} & floating-point numbers \\ "Int32" & p.~\stdpageref{Int32} & operations on 32-bit integers \\ "Int64" & p.~\stdpageref{Int64} & operations on 64-bit integers \\ "Nativeint" & p.~\stdpageref{Nativeint} & operations on platform-native integers \end{tabular} \subsubsection*{sss:stdlib-io}{input/output:} \begin{tabular}{lll} "In_channel" & p.~\stdpageref{In_channel} & input channels \\ "Out_channel" & p.~\stdpageref{Out_channel} & output channels \\ "Format" & p.~\stdpageref{Format} & pretty printing with automatic indentation and line breaking \\ "Marshal" & p.~\stdpageref{Marshal} & marshaling of data structures \\ "Printf" & p.~\stdpageref{Printf} & formatting printing functions \\ "Scanf" & p.~\stdpageref{Scanf} & formatted input functions \\ "Digest" & p.~\stdpageref{Digest} & MD5 message digest \\ \end{tabular} \subsubsection*{sss:stdlib-parsing}{Parsing:} \begin{tabular}{lll} "Lexing" & p.~\stdpageref{Lexing} & the run-time library for lexers generated by "ocamllex" \\ "Parsing" & p.~\stdpageref{Parsing} & the run-time library for parsers generated by "ocamlyacc" \\ \end{tabular} \subsubsection*{sss:stdlib-system}{System interface:} \begin{tabular}{lll} "Arg" & p.~\stdpageref{Arg} & parsing of command line arguments \\ "Callback" & p.~\stdpageref{Callback} & registering OCaml functions to be called from C \\ "Filename" & p.~\stdpageref{Filename} & operations on file names \\ "Gc" & p.~\stdpageref{Gc} & memory management control and statistics \\ "Printexc" & p.~\stdpageref{Printexc} & a catch-all exception handler \\ "Sys" & p.~\stdpageref{Sys} & system interface \\ \end{tabular} \subsubsection*{sss:stdlib-multicore}{Multicore interface:} \begin{tabular}{lll} "Domain" & p.~\stdpageref{Domain} & domain spawn and join \\ "Mutex" & p.~\stdpageref{Mutex} & mutual exclusion locks \\ "Condition" & p.~\stdpageref{Condition} & condition variables \\ "Semaphore" & p.~\stdpageref{Semaphore} & semaphores \\ "Effect" & p.~\stdpageref{Effect} & deep and shallow effect handlers \\ \end{tabular} \subsubsection*{sss:stdlib-misc}{Misc:} \begin{tabular}{lll} "Fun" & p.~\stdpageref{Fun} & function values \\ "Type" & p.~\stdpageref{Type} & type introspection \\ "Repr" & p.~\stdpageref{Repr} & functions defined on the low-level representation of values \\ \end{tabular} \end{latexonly} \begin{linklist} \stddocitem{Arg}{parsing of command line arguments} \stddocitem{Array}{array operations} \stddocitem{ArrayLabels}{array operations (with labels)} \stddocitem{Atomic}{atomic references} \stddocitem{Bigarray}{large, multi-dimensional, numerical arrays} \stddocitem{Bool}{boolean values} \stddocitem{Buffer}{extensible buffers} \stddocitem{Bytes}{byte sequences} \stddocitem{BytesLabels}{byte sequences (with labels)} \stddocitem{Callback}{registering OCaml values with the C runtime} \stddocitem{Char}{character operations} \stddocitem{Complex}{complex numbers} \stddocitem{Condition}{condition variables to synchronize between threads} \stddocitem{Domain}{Domain spawn/join and domain local variables} \stddocitem{Digest}{MD5 message digest} \stddocitem{Dynarray}{Dynamic arrays} \stddocitem{Iarray}{Immutable arrays} \stddocitem{Effect}{deep and shallow effect handlers} \stddocitem{Either}{either values} \stddocitem{Ephemeron}{Ephemerons and weak hash table} \stddocitem{Filename}{operations on file names} \stddocitem{Float}{floating-point numbers} \stddocitem{Format}{pretty printing} \stddocitem{Fun}{function values} \stddocitem{Gc}{memory management control and statistics; finalized values} \stddocitem{Hashtbl}{hash tables and hash functions} \stddocitem{In_channel}{input channels} \stddocitem{Int}{integers} \stddocitem{Int32}{32-bit integers} \stddocitem{Int64}{64-bit integers} \stddocitem{Lazy}{deferred computations} \stddocitem{Lexing}{the run-time library for lexers generated by \texttt{ocamllex}} \stddocitem{List}{list operations} \stddocitem{ListLabels}{list operations (with labels)} \stddocitem{Map}{association tables over ordered types} \stddocitem{Marshal}{marshaling of data structures} \stddocitem{MoreLabels}{include modules \texttt{Hashtbl}, \texttt{Map} and \texttt{Set} with labels} \stddocitem{Mutex}{locks for mutual exclusion} \stddocitem{Nativeint}{processor-native integers} \stddocitem{Oo}{object-oriented extension} \stddocitem{Option}{option values} \stddocitem{Out_channel}{output channels} \stddocitem{Pair}{pairs of values} \stddocitem{Parsing}{the run-time library for parsers generated by \texttt{ocamlyacc}} \stddocitem{Pqueue}{priority queues} \stddocitem{Printexc}{facilities for printing exceptions} \stddocitem{Printf}{formatting printing functions} \stddocitem{Queue}{first-in first-out queues} \stddocitem{Random}{pseudo-random number generator (PRNG)} \stddocitem{Repr}{functions defined on the low-level representation of values} \stddocitem{Result}{result values} \stddocitem{Scanf}{formatted input functions} \stddocitem{Seq}{functional iterators} \stddocitem{Set}{sets over ordered types} \stddocitem{Semaphore}{semaphores, another thread synchronization mechanism} \stddocitem{Stack}{last-in first-out stacks} \stddocitem{StdLabels}{include modules \texttt{Array}, \texttt{List}, \texttt{String} and \texttt{Iarray} with labels} \stddocitem{String}{string operations} \stddocitem{StringLabels}{string operations (with labels)} \stddocitem{Sys}{system interface} \stddocitem{Type}{type introspection} \stddocitem{Uchar}{Unicode characters} \stddocitem{Unit}{unit values} \stddocitem{Weak}{arrays of weak pointers} \ifouthtml\else \input{Ocaml_operators} \fi \end{linklist}