4913 lines
62 KiB
HTML
4913 lines
62 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Stdlib</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Stdlib</H1>
|
|
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Stdlib - The OCaml Standard library.
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Stdlib
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Stdlib</B>
|
|
|
|
<BR> :
|
|
<B>sig end</B>
|
|
|
|
<P>
|
|
<P>
|
|
The OCaml Standard library.
|
|
<P>
|
|
This module is automatically opened at the beginning of each
|
|
compilation. All components of this module can therefore be
|
|
referred by their short name, without prefixing them by
|
|
<B>Stdlib</B>
|
|
|
|
.
|
|
<P>
|
|
It particular, it provides the basic operations over the built-in
|
|
types (numbers, booleans, byte sequences, strings, exceptions,
|
|
references, lists, arrays, input-output channels, ...) and the
|
|
<B>modules</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Exceptions</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val raise </I>
|
|
|
|
:
|
|
<B>exn -> 'a</B>
|
|
|
|
<P>
|
|
Raise the given exception value
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val raise_notrace </I>
|
|
|
|
:
|
|
<B>exn -> 'a</B>
|
|
|
|
<P>
|
|
A faster version
|
|
<B>raise</B>
|
|
|
|
which does not record the backtrace.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val invalid_arg </I>
|
|
|
|
:
|
|
<B>string -> 'a</B>
|
|
|
|
<P>
|
|
Raise exception
|
|
<B>Invalid_argument</B>
|
|
|
|
with the given string.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val failwith </I>
|
|
|
|
:
|
|
<B>string -> 'a</B>
|
|
|
|
<P>
|
|
Raise exception
|
|
<B>Failure</B>
|
|
|
|
with the given string.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Exit </I>
|
|
|
|
<P>
|
|
<P>
|
|
The
|
|
<B>Exit</B>
|
|
|
|
exception is not raised by any library function. It is
|
|
provided for use in your programs.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Match_failure </I>
|
|
|
|
<B>of </B>
|
|
|
|
<B>(string * int * int)</B>
|
|
|
|
<P>
|
|
<P>
|
|
Exception raised when none of the cases of a pattern-matching
|
|
apply. The arguments are the location of the match keyword in the
|
|
source code (file name, line number, column number).
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Assert_failure </I>
|
|
|
|
<B>of </B>
|
|
|
|
<B>(string * int * int)</B>
|
|
|
|
<P>
|
|
<P>
|
|
Exception raised when an assertion fails. The arguments are the
|
|
location of the assert keyword in the source code (file name, line
|
|
number, column number).
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Invalid_argument </I>
|
|
|
|
<B>of </B>
|
|
|
|
<B>string</B>
|
|
|
|
<P>
|
|
<P>
|
|
Exception raised by library functions to signal that the given
|
|
arguments do not make sense. The string gives some information to
|
|
the programmer. As a general rule, this exception should not be
|
|
caught, it denotes a programming error and the code should be
|
|
modified not to trigger it.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Failure </I>
|
|
|
|
<B>of </B>
|
|
|
|
<B>string</B>
|
|
|
|
<P>
|
|
<P>
|
|
Exception raised by library functions to signal that they are
|
|
undefined on the given arguments. The string is meant to give some
|
|
information to the programmer; you must not pattern match on the
|
|
string literal because it may change in future versions (use
|
|
Failure _ instead).
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Not_found </I>
|
|
|
|
<P>
|
|
<P>
|
|
Exception raised by search functions when the desired object could
|
|
not be found.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Out_of_memory </I>
|
|
|
|
<P>
|
|
<P>
|
|
Exception raised by the garbage collector when there is
|
|
insufficient memory to complete the computation.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Stack_overflow </I>
|
|
|
|
<P>
|
|
<P>
|
|
Exception raised by the bytecode interpreter when the evaluation
|
|
stack reaches its maximal size. This often indicates infinite or
|
|
excessively deep recursion in the user's program. (Not fully
|
|
implemented by the native-code compiler.)
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Sys_error </I>
|
|
|
|
<B>of </B>
|
|
|
|
<B>string</B>
|
|
|
|
<P>
|
|
<P>
|
|
Exception raised by the input/output functions to report an
|
|
operating system error. The string is meant to give some
|
|
information to the programmer; you must not pattern match on the
|
|
string literal because it may change in future versions (use
|
|
Sys_error _ instead).
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception End_of_file </I>
|
|
|
|
<P>
|
|
<P>
|
|
Exception raised by input functions to signal that the end of file
|
|
has been reached.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Division_by_zero </I>
|
|
|
|
<P>
|
|
<P>
|
|
Exception raised by integer division and remainder operations when
|
|
their second argument is zero.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Sys_blocked_io </I>
|
|
|
|
<P>
|
|
<P>
|
|
A special case of Sys_error raised when no I/O is possible on a
|
|
non-blocking I/O channel.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Undefined_recursive_module </I>
|
|
|
|
<B>of </B>
|
|
|
|
<B>(string * int * int)</B>
|
|
|
|
<P>
|
|
<P>
|
|
Exception raised when an ill-founded recursive module definition
|
|
is evaluated. The arguments are the location of the definition in
|
|
the source code (file name, line number, column number).
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Comparisons</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val (=) </I>
|
|
|
|
:
|
|
<B>'a -> 'a -> bool</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>e1 = e2</B>
|
|
|
|
tests for structural equality of
|
|
<B>e1</B>
|
|
|
|
and
|
|
<B>e2</B>
|
|
|
|
.
|
|
Mutable structures (e.g. references and arrays) are equal
|
|
if and only if their current contents are structurally equal,
|
|
even if the two mutable objects are not the same physical object.
|
|
Equality between functional values raises
|
|
<B>Invalid_argument</B>
|
|
|
|
.
|
|
Equality between cyclic data structures may not terminate.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (<>) </I>
|
|
|
|
:
|
|
<B>'a -> 'a -> bool</B>
|
|
|
|
<P>
|
|
Negation of
|
|
<B>(=)</B>
|
|
|
|
.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (<) </I>
|
|
|
|
:
|
|
<B>'a -> 'a -> bool</B>
|
|
|
|
<P>
|
|
See
|
|
<B>(>=)</B>
|
|
|
|
.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (>) </I>
|
|
|
|
:
|
|
<B>'a -> 'a -> bool</B>
|
|
|
|
<P>
|
|
See
|
|
<B>(>=)</B>
|
|
|
|
.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (<=) </I>
|
|
|
|
:
|
|
<B>'a -> 'a -> bool</B>
|
|
|
|
<P>
|
|
See
|
|
<B>(>=)</B>
|
|
|
|
.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (>=) </I>
|
|
|
|
:
|
|
<B>'a -> 'a -> bool</B>
|
|
|
|
<P>
|
|
Structural ordering functions. These functions coincide with
|
|
the usual orderings over integers, characters, strings, byte sequences
|
|
and floating-point numbers, and extend them to a
|
|
total ordering over all types.
|
|
The ordering is compatible with
|
|
<B>( = )</B>
|
|
|
|
. As in the case
|
|
of
|
|
<B>( = )</B>
|
|
|
|
, mutable structures are compared by contents.
|
|
Comparison between functional values raises
|
|
<B>Invalid_argument</B>
|
|
|
|
.
|
|
Comparison between cyclic structures may not terminate.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val compare </I>
|
|
|
|
:
|
|
<B>'a -> 'a -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>compare x y</B>
|
|
|
|
returns
|
|
<B>0</B>
|
|
|
|
if
|
|
<B>x</B>
|
|
|
|
is equal to
|
|
<B>y</B>
|
|
|
|
,
|
|
a negative integer if
|
|
<B>x</B>
|
|
|
|
is less than
|
|
<B>y</B>
|
|
|
|
, and a positive integer
|
|
if
|
|
<B>x</B>
|
|
|
|
is greater than
|
|
<B>y</B>
|
|
|
|
. The ordering implemented by
|
|
<B>compare</B>
|
|
|
|
is compatible with the comparison predicates
|
|
<B>=</B>
|
|
|
|
,
|
|
<B><</B>
|
|
|
|
and
|
|
<B>></B>
|
|
|
|
defined above, with one difference on the treatment of the float value
|
|
<B>nan</B>
|
|
|
|
. Namely, the comparison predicates treat
|
|
<B>nan</B>
|
|
|
|
as different from any other float value, including itself;
|
|
while
|
|
<B>compare</B>
|
|
|
|
treats
|
|
<B>nan</B>
|
|
|
|
as equal to itself and less than any
|
|
other float value. This treatment of
|
|
<B>nan</B>
|
|
|
|
ensures that
|
|
<B>compare</B>
|
|
|
|
defines a total ordering relation.
|
|
<P>
|
|
<P>
|
|
<B>compare</B>
|
|
|
|
applied to functional values may raise
|
|
<B>Invalid_argument</B>
|
|
|
|
.
|
|
<B>compare</B>
|
|
|
|
applied to cyclic structures may not terminate.
|
|
<P>
|
|
The
|
|
<B>compare</B>
|
|
|
|
function can be used as the comparison function
|
|
required by the
|
|
<B>Set.Make</B>
|
|
|
|
and
|
|
<B>Map.Make</B>
|
|
|
|
functors, as well as
|
|
the
|
|
<B>List.sort</B>
|
|
|
|
and
|
|
<B>Array.sort</B>
|
|
|
|
functions.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val min </I>
|
|
|
|
:
|
|
<B>'a -> 'a -> 'a</B>
|
|
|
|
<P>
|
|
Return the smaller of the two arguments.
|
|
The result is unspecified if one of the arguments contains
|
|
the float value
|
|
<B>nan</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val max </I>
|
|
|
|
:
|
|
<B>'a -> 'a -> 'a</B>
|
|
|
|
<P>
|
|
Return the greater of the two arguments.
|
|
The result is unspecified if one of the arguments contains
|
|
the float value
|
|
<B>nan</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (==) </I>
|
|
|
|
:
|
|
<B>'a -> 'a -> bool</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>e1 == e2</B>
|
|
|
|
tests for physical equality of
|
|
<B>e1</B>
|
|
|
|
and
|
|
<B>e2</B>
|
|
|
|
.
|
|
On mutable types such as references, arrays, byte sequences, records with
|
|
mutable fields and objects with mutable instance variables,
|
|
<B>e1 == e2</B>
|
|
|
|
is true if and only if physical modification of
|
|
<B>e1</B>
|
|
|
|
also affects
|
|
<B>e2</B>
|
|
|
|
.
|
|
On non-mutable types, the behavior of
|
|
<B>( == )</B>
|
|
|
|
is
|
|
implementation-dependent; however, it is guaranteed that
|
|
<B>e1 == e2</B>
|
|
|
|
implies
|
|
<B>compare e1 e2 = 0</B>
|
|
|
|
.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (!=) </I>
|
|
|
|
:
|
|
<B>'a -> 'a -> bool</B>
|
|
|
|
<P>
|
|
Negation of
|
|
<B>(==)</B>
|
|
|
|
.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H3>Boolean operations</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val not </I>
|
|
|
|
:
|
|
<B>bool -> bool</B>
|
|
|
|
<P>
|
|
The boolean negation.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (&&) </I>
|
|
|
|
:
|
|
<B>bool -> bool -> bool</B>
|
|
|
|
<P>
|
|
The boolean 'and'. Evaluation is sequential, left-to-right:
|
|
in
|
|
<B>e1 && e2</B>
|
|
|
|
,
|
|
<B>e1</B>
|
|
|
|
is evaluated first, and if it returns
|
|
<B>false</B>
|
|
|
|
,
|
|
<B>e2</B>
|
|
|
|
is not evaluated at all.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (&) </I>
|
|
|
|
:
|
|
<B>bool -> bool -> bool</B>
|
|
|
|
<P>
|
|
<B>Deprecated.</B>
|
|
|
|
<P>
|
|
<B>(&&)</B>
|
|
|
|
should be used instead.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (||) </I>
|
|
|
|
:
|
|
<B>bool -> bool -> bool</B>
|
|
|
|
<P>
|
|
The boolean 'or'. Evaluation is sequential, left-to-right:
|
|
in
|
|
<B>e1 || e2</B>
|
|
|
|
,
|
|
<B>e1</B>
|
|
|
|
is evaluated first, and if it returns
|
|
<B>true</B>
|
|
|
|
,
|
|
<B>e2</B>
|
|
|
|
is not evaluated at all.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (or) </I>
|
|
|
|
:
|
|
<B>bool -> bool -> bool</B>
|
|
|
|
<P>
|
|
<B>Deprecated.</B>
|
|
|
|
<P>
|
|
<B>(||)</B>
|
|
|
|
should be used instead.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H3>Debugging</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val __LOC__ </I>
|
|
|
|
:
|
|
<B>string</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>__LOC__</B>
|
|
|
|
returns the location at which this expression appears in
|
|
the file currently being parsed by the compiler, with the standard
|
|
error format of OCaml: "File %S, line %d, characters %d-%d".
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val __FILE__ </I>
|
|
|
|
:
|
|
<B>string</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>__FILE__</B>
|
|
|
|
returns the name of the file currently being
|
|
parsed by the compiler.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val __LINE__ </I>
|
|
|
|
:
|
|
<B>int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>__LINE__</B>
|
|
|
|
returns the line number at which this expression
|
|
appears in the file currently being parsed by the compiler.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val __MODULE__ </I>
|
|
|
|
:
|
|
<B>string</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>__MODULE__</B>
|
|
|
|
returns the module name of the file being
|
|
parsed by the compiler.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val __POS__ </I>
|
|
|
|
:
|
|
<B>string * int * int * int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>__POS__</B>
|
|
|
|
returns a tuple
|
|
<B>(file,lnum,cnum,enum)</B>
|
|
|
|
, corresponding
|
|
to the location at which this expression appears in the file
|
|
currently being parsed by the compiler.
|
|
<B>file</B>
|
|
|
|
is the current
|
|
filename,
|
|
<B>lnum</B>
|
|
|
|
the line number,
|
|
<B>cnum</B>
|
|
|
|
the character position in
|
|
the line and
|
|
<B>enum</B>
|
|
|
|
the last character position in the line.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val __LOC_OF__ </I>
|
|
|
|
:
|
|
<B>'a -> string * 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>__LOC_OF__ expr</B>
|
|
|
|
returns a pair
|
|
<B>(loc, expr)</B>
|
|
|
|
where
|
|
<B>loc</B>
|
|
|
|
is the
|
|
location of
|
|
<B>expr</B>
|
|
|
|
in the file currently being parsed by the
|
|
compiler, with the standard error format of OCaml: "File %S, line
|
|
%d, characters %d-%d".
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val __LINE_OF__ </I>
|
|
|
|
:
|
|
<B>'a -> int * 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>__LINE_OF__ expr</B>
|
|
|
|
returns a pair
|
|
<B>(line, expr)</B>
|
|
|
|
, where
|
|
<B>line</B>
|
|
|
|
is the
|
|
line number at which the expression
|
|
<B>expr</B>
|
|
|
|
appears in the file
|
|
currently being parsed by the compiler.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val __POS_OF__ </I>
|
|
|
|
:
|
|
<B>'a -> (string * int * int * int) * 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>__POS_OF__ expr</B>
|
|
|
|
returns a pair
|
|
<B>(loc,expr)</B>
|
|
|
|
, where
|
|
<B>loc</B>
|
|
|
|
is a
|
|
tuple
|
|
<B>(file,lnum,cnum,enum)</B>
|
|
|
|
corresponding to the location at
|
|
which the expression
|
|
<B>expr</B>
|
|
|
|
appears in the file currently being
|
|
parsed by the compiler.
|
|
<B>file</B>
|
|
|
|
is the current filename,
|
|
<B>lnum</B>
|
|
|
|
the
|
|
line number,
|
|
<B>cnum</B>
|
|
|
|
the character position in the line and
|
|
<B>enum</B>
|
|
|
|
the last character position in the line.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H3>Composition operators</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val (|>) </I>
|
|
|
|
:
|
|
<B>'a -> ('a -> 'b) -> 'b</B>
|
|
|
|
<P>
|
|
Reverse-application operator:
|
|
<B>x |> f |> g</B>
|
|
|
|
is exactly equivalent
|
|
to
|
|
<B>g (f (x))</B>
|
|
|
|
.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.01
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (@@) </I>
|
|
|
|
:
|
|
<B>('a -> 'b) -> 'a -> 'b</B>
|
|
|
|
<P>
|
|
Application operator:
|
|
<B>g @@ f @@ x</B>
|
|
|
|
is exactly equivalent to
|
|
<B>g (f (x))</B>
|
|
|
|
.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.01
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>Integer arithmetic</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
Integers are
|
|
<B>Sys.int_size</B>
|
|
|
|
bits wide.
|
|
All operations are taken modulo 2^
|
|
<B>Sys.int_size</B>
|
|
|
|
.
|
|
They do not fail on overflow.
|
|
<P>
|
|
|
|
<P>
|
|
<I>val (~-) </I>
|
|
|
|
:
|
|
<B>int -> int</B>
|
|
|
|
<P>
|
|
Unary negation. You can also write
|
|
<B>- e</B>
|
|
|
|
instead of
|
|
<B>~- e</B>
|
|
|
|
.
|
|
Unary operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (~+) </I>
|
|
|
|
:
|
|
<B>int -> int</B>
|
|
|
|
<P>
|
|
Unary addition. You can also write
|
|
<B>+ e</B>
|
|
|
|
instead of
|
|
<B>~+ e</B>
|
|
|
|
.
|
|
Unary operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
3.12.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val succ </I>
|
|
|
|
:
|
|
<B>int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>succ x</B>
|
|
|
|
is
|
|
<B>x + 1</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val pred </I>
|
|
|
|
:
|
|
<B>int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>pred x</B>
|
|
|
|
is
|
|
<B>x - 1</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (+) </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
Integer addition.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (-) </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
Integer subtraction.
|
|
Left-associative operator, , see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val ( * ) </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
Integer multiplication.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (/) </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
Integer division.
|
|
Raise
|
|
<B>Division_by_zero</B>
|
|
|
|
if the second argument is 0.
|
|
Integer division rounds the real quotient of its arguments towards zero.
|
|
More precisely, if
|
|
<B>x >= 0</B>
|
|
|
|
and
|
|
<B>y > 0</B>
|
|
|
|
,
|
|
<B>x / y</B>
|
|
|
|
is the greatest integer
|
|
less than or equal to the real quotient of
|
|
<B>x</B>
|
|
|
|
by
|
|
<B>y</B>
|
|
|
|
. Moreover,
|
|
<B>(- x) / y = x / (- y) = - (x / y)</B>
|
|
|
|
.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (mod) </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
Integer remainder. If
|
|
<B>y</B>
|
|
|
|
is not zero, the result
|
|
of
|
|
<B>x mod y</B>
|
|
|
|
satisfies the following properties:
|
|
<B>x = (x / y) * y + x mod y</B>
|
|
|
|
and
|
|
<B>abs(x mod y) <= abs(y) - 1</B>
|
|
|
|
.
|
|
If
|
|
<B>y = 0</B>
|
|
|
|
,
|
|
<B>x mod y</B>
|
|
|
|
raises
|
|
<B>Division_by_zero</B>
|
|
|
|
.
|
|
Note that
|
|
<B>x mod y</B>
|
|
|
|
is negative only if
|
|
<B>x < 0</B>
|
|
|
|
.
|
|
Raise
|
|
<B>Division_by_zero</B>
|
|
|
|
if
|
|
<B>y</B>
|
|
|
|
is zero.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val abs </I>
|
|
|
|
:
|
|
<B>int -> int</B>
|
|
|
|
<P>
|
|
Return the absolute value of the argument. Note that this may be
|
|
negative if the argument is
|
|
<B>min_int</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val max_int </I>
|
|
|
|
:
|
|
<B>int</B>
|
|
|
|
<P>
|
|
The greatest representable integer.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val min_int </I>
|
|
|
|
:
|
|
<B>int</B>
|
|
|
|
<P>
|
|
The smallest representable integer.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H3>Bitwise operations</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val (land) </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
Bitwise logical and.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (lor) </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
Bitwise logical or.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (lxor) </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
Bitwise logical exclusive or.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val lnot </I>
|
|
|
|
:
|
|
<B>int -> int</B>
|
|
|
|
<P>
|
|
Bitwise logical negation.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (lsl) </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>n lsl m</B>
|
|
|
|
shifts
|
|
<B>n</B>
|
|
|
|
to the left by
|
|
<B>m</B>
|
|
|
|
bits.
|
|
The result is unspecified if
|
|
<B>m < 0</B>
|
|
|
|
or
|
|
<B>m > Sys.int_size</B>
|
|
|
|
.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (lsr) </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>n lsr m</B>
|
|
|
|
shifts
|
|
<B>n</B>
|
|
|
|
to the right by
|
|
<B>m</B>
|
|
|
|
bits.
|
|
This is a logical shift: zeroes are inserted regardless of
|
|
the sign of
|
|
<B>n</B>
|
|
|
|
.
|
|
The result is unspecified if
|
|
<B>m < 0</B>
|
|
|
|
or
|
|
<B>m > Sys.int_size</B>
|
|
|
|
.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (asr) </I>
|
|
|
|
:
|
|
<B>int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>n asr m</B>
|
|
|
|
shifts
|
|
<B>n</B>
|
|
|
|
to the right by
|
|
<B>m</B>
|
|
|
|
bits.
|
|
This is an arithmetic shift: the sign bit of
|
|
<B>n</B>
|
|
|
|
is replicated.
|
|
The result is unspecified if
|
|
<B>m < 0</B>
|
|
|
|
or
|
|
<B>m > Sys.int_size</B>
|
|
|
|
.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H3>Floating-point arithmetic</H3>
|
|
|
|
<P>
|
|
OCaml's floating-point numbers follow the
|
|
IEEE 754 standard, using double precision (64 bits) numbers.
|
|
Floating-point operations never raise an exception on overflow,
|
|
underflow, division by zero, etc. Instead, special IEEE numbers
|
|
are returned as appropriate, such as
|
|
<B>infinity</B>
|
|
|
|
for
|
|
<B>1.0 /. 0.0</B>
|
|
|
|
,
|
|
<B>neg_infinity</B>
|
|
|
|
for
|
|
<B>-1.0 /. 0.0</B>
|
|
|
|
, and
|
|
<B>nan</B>
|
|
|
|
('not a number')
|
|
for
|
|
<B>0.0 /. 0.0</B>
|
|
|
|
. These special numbers then propagate through
|
|
floating-point computations as expected: for instance,
|
|
<B>1.0 /. infinity</B>
|
|
|
|
is
|
|
<B>0.0</B>
|
|
|
|
, and any arithmetic operation with
|
|
<B>nan</B>
|
|
|
|
as argument returns
|
|
<B>nan</B>
|
|
|
|
as result.
|
|
<P>
|
|
|
|
<P>
|
|
<I>val (~-.) </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Unary negation. You can also write
|
|
<B>-. e</B>
|
|
|
|
instead of
|
|
<B>~-. e</B>
|
|
|
|
.
|
|
Unary operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (~+.) </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Unary addition. You can also write
|
|
<B>+. e</B>
|
|
|
|
instead of
|
|
<B>~+. e</B>
|
|
|
|
.
|
|
Unary operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
3.12.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (+.) </I>
|
|
|
|
:
|
|
<B>float -> float -> float</B>
|
|
|
|
<P>
|
|
Floating-point addition.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (-.) </I>
|
|
|
|
:
|
|
<B>float -> float -> float</B>
|
|
|
|
<P>
|
|
Floating-point subtraction.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val ( *. ) </I>
|
|
|
|
:
|
|
<B>float -> float -> float</B>
|
|
|
|
<P>
|
|
Floating-point multiplication.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (/.) </I>
|
|
|
|
:
|
|
<B>float -> float -> float</B>
|
|
|
|
<P>
|
|
Floating-point division.
|
|
Left-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val ( ** ) </I>
|
|
|
|
:
|
|
<B>float -> float -> float</B>
|
|
|
|
<P>
|
|
Exponentiation.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val sqrt </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Square root.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val exp </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Exponential.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val log </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Natural logarithm.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val log10 </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Base 10 logarithm.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val expm1 </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>expm1 x</B>
|
|
|
|
computes
|
|
<B>exp x -. 1.0</B>
|
|
|
|
, giving numerically-accurate results
|
|
even if
|
|
<B>x</B>
|
|
|
|
is close to
|
|
<B>0.0</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
3.12.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val log1p </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>log1p x</B>
|
|
|
|
computes
|
|
<B>log(1.0 +. x)</B>
|
|
|
|
(natural logarithm),
|
|
giving numerically-accurate results even if
|
|
<B>x</B>
|
|
|
|
is close to
|
|
<B>0.0</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
3.12.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val cos </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Cosine. Argument is in radians.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val sin </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Sine. Argument is in radians.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val tan </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Tangent. Argument is in radians.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val acos </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Arc cosine. The argument must fall within the range
|
|
<B>[-1.0, 1.0]</B>
|
|
|
|
.
|
|
Result is in radians and is between
|
|
<B>0.0</B>
|
|
|
|
and
|
|
<B>pi</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val asin </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Arc sine. The argument must fall within the range
|
|
<B>[-1.0, 1.0]</B>
|
|
|
|
.
|
|
Result is in radians and is between
|
|
<B>-pi/2</B>
|
|
|
|
and
|
|
<B>pi/2</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val atan </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Arc tangent.
|
|
Result is in radians and is between
|
|
<B>-pi/2</B>
|
|
|
|
and
|
|
<B>pi/2</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val atan2 </I>
|
|
|
|
:
|
|
<B>float -> float -> float</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>atan2 y x</B>
|
|
|
|
returns the arc tangent of
|
|
<B>y /. x</B>
|
|
|
|
. The signs of
|
|
<B>x</B>
|
|
|
|
and
|
|
<B>y</B>
|
|
|
|
are used to determine the quadrant of the result.
|
|
Result is in radians and is between
|
|
<B>-pi</B>
|
|
|
|
and
|
|
<B>pi</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val hypot </I>
|
|
|
|
:
|
|
<B>float -> float -> float</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>hypot x y</B>
|
|
|
|
returns
|
|
<B>sqrt(x *. x + y *. y)</B>
|
|
|
|
, that is, the length
|
|
of the hypotenuse of a right-angled triangle with sides of length
|
|
<B>x</B>
|
|
|
|
and
|
|
<B>y</B>
|
|
|
|
, or, equivalently, the distance of the point
|
|
<B>(x,y)</B>
|
|
|
|
to origin. If one of
|
|
<B>x</B>
|
|
|
|
or
|
|
<B>y</B>
|
|
|
|
is infinite, returns
|
|
<B>infinity</B>
|
|
|
|
even if the other is
|
|
<B>nan</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.00.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val cosh </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Hyperbolic cosine. Argument is in radians.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val sinh </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Hyperbolic sine. Argument is in radians.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val tanh </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Hyperbolic tangent. Argument is in radians.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val ceil </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Round above to an integer value.
|
|
<B>ceil f</B>
|
|
|
|
returns the least integer value greater than or equal to
|
|
<B>f</B>
|
|
|
|
.
|
|
The result is returned as a float.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val floor </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
Round below to an integer value.
|
|
<B>floor f</B>
|
|
|
|
returns the greatest integer value less than or
|
|
equal to
|
|
<B>f</B>
|
|
|
|
.
|
|
The result is returned as a float.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val abs_float </I>
|
|
|
|
:
|
|
<B>float -> float</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>abs_float f</B>
|
|
|
|
returns the absolute value of
|
|
<B>f</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val copysign </I>
|
|
|
|
:
|
|
<B>float -> float -> float</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>copysign x y</B>
|
|
|
|
returns a float whose absolute value is that of
|
|
<B>x</B>
|
|
|
|
and whose sign is that of
|
|
<B>y</B>
|
|
|
|
. If
|
|
<B>x</B>
|
|
|
|
is
|
|
<B>nan</B>
|
|
|
|
, returns
|
|
<B>nan</B>
|
|
|
|
.
|
|
If
|
|
<B>y</B>
|
|
|
|
is
|
|
<B>nan</B>
|
|
|
|
, returns either
|
|
<B>x</B>
|
|
|
|
or
|
|
<B>-. x</B>
|
|
|
|
, but it is not
|
|
specified which.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.00.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val mod_float </I>
|
|
|
|
:
|
|
<B>float -> float -> float</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>mod_float a b</B>
|
|
|
|
returns the remainder of
|
|
<B>a</B>
|
|
|
|
with respect to
|
|
<B>b</B>
|
|
|
|
. The returned value is
|
|
<B>a -. n *. b</B>
|
|
|
|
, where
|
|
<B>n</B>
|
|
|
|
is the quotient
|
|
<B>a /. b</B>
|
|
|
|
rounded towards zero to an integer.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val frexp </I>
|
|
|
|
:
|
|
<B>float -> float * int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>frexp f</B>
|
|
|
|
returns the pair of the significant
|
|
and the exponent of
|
|
<B>f</B>
|
|
|
|
. When
|
|
<B>f</B>
|
|
|
|
is zero, the
|
|
significant
|
|
<B>x</B>
|
|
|
|
and the exponent
|
|
<B>n</B>
|
|
|
|
of
|
|
<B>f</B>
|
|
|
|
are equal to
|
|
zero. When
|
|
<B>f</B>
|
|
|
|
is non-zero, they are defined by
|
|
<B>f = x *. 2 ** n</B>
|
|
|
|
and
|
|
<B>0.5 <= x < 1.0</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val ldexp </I>
|
|
|
|
:
|
|
<B>float -> int -> float</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>ldexp x n</B>
|
|
|
|
returns
|
|
<B>x *. 2 ** n</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val modf </I>
|
|
|
|
:
|
|
<B>float -> float * float</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>modf f</B>
|
|
|
|
returns the pair of the fractional and integral
|
|
part of
|
|
<B>f</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val float </I>
|
|
|
|
:
|
|
<B>int -> float</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>float_of_int</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val float_of_int </I>
|
|
|
|
:
|
|
<B>int -> float</B>
|
|
|
|
<P>
|
|
Convert an integer to floating-point.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val truncate </I>
|
|
|
|
:
|
|
<B>float -> int</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>int_of_float</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val int_of_float </I>
|
|
|
|
:
|
|
<B>float -> int</B>
|
|
|
|
<P>
|
|
Truncate the given floating-point number to an integer.
|
|
The result is unspecified if the argument is
|
|
<B>nan</B>
|
|
|
|
or falls outside the
|
|
range of representable integers.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val infinity </I>
|
|
|
|
:
|
|
<B>float</B>
|
|
|
|
<P>
|
|
Positive infinity.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val neg_infinity </I>
|
|
|
|
:
|
|
<B>float</B>
|
|
|
|
<P>
|
|
Negative infinity.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val nan </I>
|
|
|
|
:
|
|
<B>float</B>
|
|
|
|
<P>
|
|
A special floating-point value denoting the result of an
|
|
undefined operation such as
|
|
<B>0.0 /. 0.0</B>
|
|
|
|
. Stands for
|
|
'not a number'. Any floating-point operation with
|
|
<B>nan</B>
|
|
|
|
as
|
|
argument returns
|
|
<B>nan</B>
|
|
|
|
as result. As for floating-point comparisons,
|
|
<B>=</B>
|
|
|
|
,
|
|
<B><</B>
|
|
|
|
,
|
|
<B><=</B>
|
|
|
|
,
|
|
<B>></B>
|
|
|
|
and
|
|
<B>>=</B>
|
|
|
|
return
|
|
<B>false</B>
|
|
|
|
and
|
|
<B><></B>
|
|
|
|
returns
|
|
<B>true</B>
|
|
|
|
if one or both of their arguments is
|
|
<B>nan</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val max_float </I>
|
|
|
|
:
|
|
<B>float</B>
|
|
|
|
<P>
|
|
The largest positive finite value of type
|
|
<B>float</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val min_float </I>
|
|
|
|
:
|
|
<B>float</B>
|
|
|
|
<P>
|
|
The smallest positive, non-zero, non-denormalized value of type
|
|
<B>float</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val epsilon_float </I>
|
|
|
|
:
|
|
<B>float</B>
|
|
|
|
<P>
|
|
The difference between
|
|
<B>1.0</B>
|
|
|
|
and the smallest exactly representable
|
|
floating-point number greater than
|
|
<B>1.0</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<I>type fpclass </I>
|
|
|
|
=
|
|
<BR> | FP_normal (* Normal number, none of the below
|
|
<BR> *)
|
|
<BR> | FP_subnormal (* Number very close to 0.0, has reduced precision
|
|
<BR> *)
|
|
<BR> | FP_zero (* Number is 0.0 or -0.0
|
|
<BR> *)
|
|
<BR> | FP_infinite (* Number is positive or negative infinity
|
|
<BR> *)
|
|
<BR> | FP_nan (* Not a number: result of an undefined operation
|
|
<BR> *)
|
|
<BR>
|
|
<P>
|
|
The five classes of floating-point numbers, as determined by
|
|
the
|
|
<B>classify_float</B>
|
|
|
|
function.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val classify_float </I>
|
|
|
|
:
|
|
<B>float -> fpclass</B>
|
|
|
|
<P>
|
|
Return the class of the given floating-point number:
|
|
normal, subnormal, zero, infinite, or not a number.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H3>String operations</H3>
|
|
|
|
<P>
|
|
More string operations are provided in module
|
|
<B>String</B>
|
|
|
|
.
|
|
<P>
|
|
|
|
<P>
|
|
<I>val (^) </I>
|
|
|
|
:
|
|
<B>string -> string -> string</B>
|
|
|
|
<P>
|
|
String concatenation.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAN"> </A>
|
|
<H3>Character operations</H3>
|
|
|
|
<P>
|
|
More character operations are provided in module
|
|
<B>Char</B>
|
|
|
|
.
|
|
<P>
|
|
|
|
<P>
|
|
<I>val int_of_char </I>
|
|
|
|
:
|
|
<B>char -> int</B>
|
|
|
|
<P>
|
|
Return the ASCII code of the argument.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val char_of_int </I>
|
|
|
|
:
|
|
<B>int -> char</B>
|
|
|
|
<P>
|
|
Return the character with the given ASCII code.
|
|
Raise
|
|
<B>Invalid_argument char_of_int</B>
|
|
|
|
if the argument is
|
|
outside the range 0--255.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAO"> </A>
|
|
<H3>Unit operations</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val ignore </I>
|
|
|
|
:
|
|
<B>'a -> unit</B>
|
|
|
|
<P>
|
|
Discard the value of its argument and return
|
|
<B>()</B>
|
|
|
|
.
|
|
For instance,
|
|
<B>ignore(f x)</B>
|
|
|
|
discards the result of
|
|
the side-effecting function
|
|
<B>f</B>
|
|
|
|
. It is equivalent to
|
|
<B>f x; ()</B>
|
|
|
|
, except that the latter may generate a
|
|
compiler warning; writing
|
|
<B>ignore(f x)</B>
|
|
|
|
instead
|
|
avoids the warning.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAP"> </A>
|
|
<H3>String conversion functions</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val string_of_bool </I>
|
|
|
|
:
|
|
<B>bool -> string</B>
|
|
|
|
<P>
|
|
Return the string representation of a boolean. As the returned values
|
|
may be shared, the user should not modify them directly.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val bool_of_string_opt </I>
|
|
|
|
:
|
|
<B>string -> bool option</B>
|
|
|
|
<P>
|
|
Convert the given string to a boolean.
|
|
<P>
|
|
Return
|
|
<B>None</B>
|
|
|
|
if the string is not
|
|
<B>true</B>
|
|
|
|
or
|
|
<B>false</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.05
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val bool_of_string </I>
|
|
|
|
:
|
|
<B>string -> bool</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>bool_of_string_opt</B>
|
|
|
|
, but raise
|
|
<B>Invalid_argument bool_of_string</B>
|
|
|
|
instead of returning
|
|
<B>None</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val string_of_int </I>
|
|
|
|
:
|
|
<B>int -> string</B>
|
|
|
|
<P>
|
|
Return the string representation of an integer, in decimal.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val int_of_string_opt </I>
|
|
|
|
:
|
|
<B>string -> int option</B>
|
|
|
|
<P>
|
|
Convert the given string to an integer.
|
|
The string is read in decimal (by default, or if the string
|
|
begins with
|
|
<B>0u</B>
|
|
|
|
), in hexadecimal (if it begins with
|
|
<B>0x</B>
|
|
|
|
or
|
|
<B>0X</B>
|
|
|
|
), in octal (if it begins with
|
|
<B>0o</B>
|
|
|
|
or
|
|
<B>0O</B>
|
|
|
|
), or in binary
|
|
(if it begins with
|
|
<B>0b</B>
|
|
|
|
or
|
|
<B>0B</B>
|
|
|
|
).
|
|
<P>
|
|
The
|
|
<B>0u</B>
|
|
|
|
prefix reads the input as an unsigned integer in the range
|
|
<B>[0, 2*max_int+1]</B>
|
|
|
|
. If the input exceeds
|
|
<B>max_int</B>
|
|
|
|
it is converted to the signed integer
|
|
<B>min_int + input - max_int - 1</B>
|
|
|
|
.
|
|
<P>
|
|
The
|
|
<B>_</B>
|
|
|
|
(underscore) character can appear anywhere in the string
|
|
and is ignored.
|
|
<P>
|
|
Return
|
|
<B>None</B>
|
|
|
|
if the given string is not a valid representation of an
|
|
integer, or if the integer represented exceeds the range of integers
|
|
representable in type
|
|
<B>int</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.05
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val int_of_string </I>
|
|
|
|
:
|
|
<B>string -> int</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>int_of_string_opt</B>
|
|
|
|
, but raise
|
|
<B>Failure int_of_string</B>
|
|
|
|
instead of returning
|
|
<B>None</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val string_of_float </I>
|
|
|
|
:
|
|
<B>float -> string</B>
|
|
|
|
<P>
|
|
Return the string representation of a floating-point number.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val float_of_string_opt </I>
|
|
|
|
:
|
|
<B>string -> float option</B>
|
|
|
|
<P>
|
|
Convert the given string to a float. The string is read in decimal
|
|
(by default) or in hexadecimal (marked by
|
|
<B>0x</B>
|
|
|
|
or
|
|
<B>0X</B>
|
|
|
|
).
|
|
<P>
|
|
The format of decimal floating-point numbers is
|
|
<B>[-] dd.ddd (e|E) [+|-] dd </B>
|
|
|
|
, where
|
|
<B>d</B>
|
|
|
|
stands for a decimal digit.
|
|
<P>
|
|
The format of hexadecimal floating-point numbers is
|
|
<B>[-] 0(x|X) hh.hhh (p|P) [+|-] dd </B>
|
|
|
|
, where
|
|
<B>h</B>
|
|
|
|
stands for an
|
|
hexadecimal digit and
|
|
<B>d</B>
|
|
|
|
for a decimal digit.
|
|
<P>
|
|
In both cases, at least one of the integer and fractional parts must be
|
|
given; the exponent part is optional.
|
|
<P>
|
|
The
|
|
<B>_</B>
|
|
|
|
(underscore) character can appear anywhere in the string
|
|
and is ignored.
|
|
<P>
|
|
Depending on the execution platforms, other representations of
|
|
floating-point numbers can be accepted, but should not be relied upon.
|
|
<P>
|
|
Return
|
|
<B>None</B>
|
|
|
|
if the given string is not a valid representation of a float.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.05
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val float_of_string </I>
|
|
|
|
:
|
|
<B>string -> float</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>float_of_string_opt</B>
|
|
|
|
, but raise
|
|
<B>Failure float_of_string</B>
|
|
|
|
instead of returning
|
|
<B>None</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAQ"> </A>
|
|
<H3>Pair operations</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val fst </I>
|
|
|
|
:
|
|
<B>'a * 'b -> 'a</B>
|
|
|
|
<P>
|
|
Return the first component of a pair.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val snd </I>
|
|
|
|
:
|
|
<B>'a * 'b -> 'b</B>
|
|
|
|
<P>
|
|
Return the second component of a pair.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAR"> </A>
|
|
<H3>List operations</H3>
|
|
|
|
<P>
|
|
More list operations are provided in module
|
|
<B>List</B>
|
|
|
|
.
|
|
<P>
|
|
|
|
<P>
|
|
<I>val (@) </I>
|
|
|
|
:
|
|
<B>'a list -> 'a list -> 'a list</B>
|
|
|
|
<P>
|
|
List concatenation. Not tail-recursive (length of the first argument).
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAS"> </A>
|
|
<H3>Input/output</H3>
|
|
|
|
Note: all input/output functions can raise
|
|
<B>Sys_error</B>
|
|
|
|
when the system
|
|
calls they invoke fail.
|
|
<P>
|
|
|
|
<I>type in_channel </I>
|
|
|
|
<P>
|
|
<P>
|
|
The type of input channel.
|
|
<P>
|
|
<P>
|
|
<I>type out_channel </I>
|
|
|
|
<P>
|
|
<P>
|
|
The type of output channel.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val stdin </I>
|
|
|
|
:
|
|
<B>in_channel</B>
|
|
|
|
<P>
|
|
The standard input for the process.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val stdout </I>
|
|
|
|
:
|
|
<B>out_channel</B>
|
|
|
|
<P>
|
|
The standard output for the process.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val stderr </I>
|
|
|
|
:
|
|
<B>out_channel</B>
|
|
|
|
<P>
|
|
The standard error output for the process.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAT"> </A>
|
|
<H3>Output functions on standard output</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val print_char </I>
|
|
|
|
:
|
|
<B>char -> unit</B>
|
|
|
|
<P>
|
|
Print a character on standard output.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val print_string </I>
|
|
|
|
:
|
|
<B>string -> unit</B>
|
|
|
|
<P>
|
|
Print a string on standard output.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val print_bytes </I>
|
|
|
|
:
|
|
<B>bytes -> unit</B>
|
|
|
|
<P>
|
|
Print a byte sequence on standard output.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val print_int </I>
|
|
|
|
:
|
|
<B>int -> unit</B>
|
|
|
|
<P>
|
|
Print an integer, in decimal, on standard output.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val print_float </I>
|
|
|
|
:
|
|
<B>float -> unit</B>
|
|
|
|
<P>
|
|
Print a floating-point number, in decimal, on standard output.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val print_endline </I>
|
|
|
|
:
|
|
<B>string -> unit</B>
|
|
|
|
<P>
|
|
Print a string, followed by a newline character, on
|
|
standard output and flush standard output.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val print_newline </I>
|
|
|
|
:
|
|
<B>unit -> unit</B>
|
|
|
|
<P>
|
|
Print a newline character on standard output, and flush
|
|
standard output. This can be used to simulate line
|
|
buffering of standard output.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAU"> </A>
|
|
<H3>Output functions on standard error</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val prerr_char </I>
|
|
|
|
:
|
|
<B>char -> unit</B>
|
|
|
|
<P>
|
|
Print a character on standard error.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val prerr_string </I>
|
|
|
|
:
|
|
<B>string -> unit</B>
|
|
|
|
<P>
|
|
Print a string on standard error.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val prerr_bytes </I>
|
|
|
|
:
|
|
<B>bytes -> unit</B>
|
|
|
|
<P>
|
|
Print a byte sequence on standard error.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val prerr_int </I>
|
|
|
|
:
|
|
<B>int -> unit</B>
|
|
|
|
<P>
|
|
Print an integer, in decimal, on standard error.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val prerr_float </I>
|
|
|
|
:
|
|
<B>float -> unit</B>
|
|
|
|
<P>
|
|
Print a floating-point number, in decimal, on standard error.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val prerr_endline </I>
|
|
|
|
:
|
|
<B>string -> unit</B>
|
|
|
|
<P>
|
|
Print a string, followed by a newline character on standard
|
|
error and flush standard error.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val prerr_newline </I>
|
|
|
|
:
|
|
<B>unit -> unit</B>
|
|
|
|
<P>
|
|
Print a newline character on standard error, and flush
|
|
standard error.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAV"> </A>
|
|
<H3>Input functions on standard input</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val read_line </I>
|
|
|
|
:
|
|
<B>unit -> string</B>
|
|
|
|
<P>
|
|
Flush standard output, then read characters from standard input
|
|
until a newline character is encountered. Return the string of
|
|
all characters read, without the newline character at the end.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val read_int_opt </I>
|
|
|
|
:
|
|
<B>unit -> int option</B>
|
|
|
|
<P>
|
|
Flush standard output, then read one line from standard input
|
|
and convert it to an integer.
|
|
<P>
|
|
Return
|
|
<B>None</B>
|
|
|
|
if the line read is not a valid representation of an integer.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.05
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val read_int </I>
|
|
|
|
:
|
|
<B>unit -> int</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>read_int_opt</B>
|
|
|
|
, but raise
|
|
<B>Failure int_of_string</B>
|
|
|
|
instead of returning
|
|
<B>None</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val read_float_opt </I>
|
|
|
|
:
|
|
<B>unit -> float option</B>
|
|
|
|
<P>
|
|
Flush standard output, then read one line from standard input
|
|
and convert it to a floating-point number.
|
|
<P>
|
|
Return
|
|
<B>None</B>
|
|
|
|
if the line read is not a valid representation of a
|
|
floating-point number.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.05.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val read_float </I>
|
|
|
|
:
|
|
<B>unit -> float</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>read_float_opt</B>
|
|
|
|
, but raise
|
|
<B>Failure float_of_string</B>
|
|
|
|
instead of returning
|
|
<B>None</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAW"> </A>
|
|
<H3>General output functions</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<I>type open_flag </I>
|
|
|
|
=
|
|
<BR> | Open_rdonly (* open for reading.
|
|
<BR> *)
|
|
<BR> | Open_wronly (* open for writing.
|
|
<BR> *)
|
|
<BR> | Open_append (* open for appending: always write at end of file.
|
|
<BR> *)
|
|
<BR> | Open_creat (* create the file if it does not exist.
|
|
<BR> *)
|
|
<BR> | Open_trunc (* empty the file if it already exists.
|
|
<BR> *)
|
|
<BR> | Open_excl (* fail if Open_creat and the file already exists.
|
|
<BR> *)
|
|
<BR> | Open_binary (* open in binary mode (no conversion).
|
|
<BR> *)
|
|
<BR> | Open_text (* open in text mode (may perform conversions).
|
|
<BR> *)
|
|
<BR> | Open_nonblock (* open in non-blocking mode.
|
|
<BR> *)
|
|
<BR>
|
|
<P>
|
|
Opening modes for
|
|
<B>open_out_gen</B>
|
|
|
|
and
|
|
<B>open_in_gen</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val open_out </I>
|
|
|
|
:
|
|
<B>string -> out_channel</B>
|
|
|
|
<P>
|
|
Open the named file for writing, and return a new output channel
|
|
on that file, positioned at the beginning of the file. The
|
|
file is truncated to zero length if it already exists. It
|
|
is created if it does not already exists.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val open_out_bin </I>
|
|
|
|
:
|
|
<B>string -> out_channel</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>open_out</B>
|
|
|
|
, but the file is opened in binary mode,
|
|
so that no translation takes place during writes. On operating
|
|
systems that do not distinguish between text mode and binary
|
|
mode, this function behaves like
|
|
<B>open_out</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val open_out_gen </I>
|
|
|
|
:
|
|
<B>open_flag list -> int -> string -> out_channel</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>open_out_gen mode perm filename</B>
|
|
|
|
opens the named file for writing,
|
|
as described above. The extra argument
|
|
<B>mode</B>
|
|
|
|
specifies the opening mode. The extra argument
|
|
<B>perm</B>
|
|
|
|
specifies
|
|
the file permissions, in case the file must be created.
|
|
<B>open_out</B>
|
|
|
|
and
|
|
<B>open_out_bin</B>
|
|
|
|
are special
|
|
cases of this function.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val flush </I>
|
|
|
|
:
|
|
<B>out_channel -> unit</B>
|
|
|
|
<P>
|
|
Flush the buffer associated with the given output channel,
|
|
performing all pending writes on that channel.
|
|
Interactive programs must be careful about flushing standard
|
|
output and standard error at the right time.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val flush_all </I>
|
|
|
|
:
|
|
<B>unit -> unit</B>
|
|
|
|
<P>
|
|
Flush all open output channels; ignore errors.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val output_char </I>
|
|
|
|
:
|
|
<B>out_channel -> char -> unit</B>
|
|
|
|
<P>
|
|
Write the character on the given output channel.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val output_string </I>
|
|
|
|
:
|
|
<B>out_channel -> string -> unit</B>
|
|
|
|
<P>
|
|
Write the string on the given output channel.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val output_bytes </I>
|
|
|
|
:
|
|
<B>out_channel -> bytes -> unit</B>
|
|
|
|
<P>
|
|
Write the byte sequence on the given output channel.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val output </I>
|
|
|
|
:
|
|
<B>out_channel -> bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>output oc buf pos len</B>
|
|
|
|
writes
|
|
<B>len</B>
|
|
|
|
characters from byte sequence
|
|
<B>buf</B>
|
|
|
|
,
|
|
starting at offset
|
|
<B>pos</B>
|
|
|
|
, to the given output channel
|
|
<B>oc</B>
|
|
|
|
.
|
|
Raise
|
|
<B>Invalid_argument output</B>
|
|
|
|
if
|
|
<B>pos</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
do not
|
|
designate a valid range of
|
|
<B>buf</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val output_substring </I>
|
|
|
|
:
|
|
<B>out_channel -> string -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>output</B>
|
|
|
|
but take a string as argument instead of
|
|
a byte sequence.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val output_byte </I>
|
|
|
|
:
|
|
<B>out_channel -> int -> unit</B>
|
|
|
|
<P>
|
|
Write one 8-bit integer (as the single character with that code)
|
|
on the given output channel. The given integer is taken modulo
|
|
256.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val output_binary_int </I>
|
|
|
|
:
|
|
<B>out_channel -> int -> unit</B>
|
|
|
|
<P>
|
|
Write one integer in binary format (4 bytes, big-endian)
|
|
on the given output channel.
|
|
The given integer is taken modulo 2^32.
|
|
The only reliable way to read it back is through the
|
|
<B>input_binary_int</B>
|
|
|
|
function. The format is compatible across
|
|
all machines for a given version of OCaml.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val output_value </I>
|
|
|
|
:
|
|
<B>out_channel -> 'a -> unit</B>
|
|
|
|
<P>
|
|
Write the representation of a structured value of any type
|
|
to a channel. Circularities and sharing inside the value
|
|
are detected and preserved. The object can be read back,
|
|
by the function
|
|
<B>input_value</B>
|
|
|
|
. See the description of module
|
|
<B>Marshal</B>
|
|
|
|
for more information.
|
|
<B>output_value</B>
|
|
|
|
is equivalent
|
|
to
|
|
<B>Marshal.to_channel</B>
|
|
|
|
with an empty list of flags.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val seek_out </I>
|
|
|
|
:
|
|
<B>out_channel -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>seek_out chan pos</B>
|
|
|
|
sets the current writing position to
|
|
<B>pos</B>
|
|
|
|
for channel
|
|
<B>chan</B>
|
|
|
|
. This works only for regular files. On
|
|
files of other kinds (such as terminals, pipes and sockets),
|
|
the behavior is unspecified.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val pos_out </I>
|
|
|
|
:
|
|
<B>out_channel -> int</B>
|
|
|
|
<P>
|
|
Return the current writing position for the given channel. Does
|
|
not work on channels opened with the
|
|
<B>Open_append</B>
|
|
|
|
flag (returns
|
|
unspecified results).
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val out_channel_length </I>
|
|
|
|
:
|
|
<B>out_channel -> int</B>
|
|
|
|
<P>
|
|
Return the size (number of characters) of the regular file
|
|
on which the given channel is opened. If the channel is opened
|
|
on a file that is not a regular file, the result is meaningless.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val close_out </I>
|
|
|
|
:
|
|
<B>out_channel -> unit</B>
|
|
|
|
<P>
|
|
Close the given channel, flushing all buffered write operations.
|
|
Output functions raise a
|
|
<B>Sys_error</B>
|
|
|
|
exception when they are
|
|
applied to a closed output channel, except
|
|
<B>close_out</B>
|
|
|
|
and
|
|
<B>flush</B>
|
|
|
|
,
|
|
which do nothing when applied to an already closed channel.
|
|
Note that
|
|
<B>close_out</B>
|
|
|
|
may raise
|
|
<B>Sys_error</B>
|
|
|
|
if the operating
|
|
system signals an error when flushing or closing.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val close_out_noerr </I>
|
|
|
|
:
|
|
<B>out_channel -> unit</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>close_out</B>
|
|
|
|
, but ignore all errors.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_binary_mode_out </I>
|
|
|
|
:
|
|
<B>out_channel -> bool -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_binary_mode_out oc true</B>
|
|
|
|
sets the channel
|
|
<B>oc</B>
|
|
|
|
to binary
|
|
mode: no translations take place during output.
|
|
<B>set_binary_mode_out oc false</B>
|
|
|
|
sets the channel
|
|
<B>oc</B>
|
|
|
|
to text
|
|
mode: depending on the operating system, some translations
|
|
may take place during output. For instance, under Windows,
|
|
end-of-lines will be translated from
|
|
<B>\n</B>
|
|
|
|
to
|
|
<B>\r\n</B>
|
|
|
|
.
|
|
This function has no effect under operating systems that
|
|
do not distinguish between text mode and binary mode.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAX"> </A>
|
|
<H3>General input functions</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val open_in </I>
|
|
|
|
:
|
|
<B>string -> in_channel</B>
|
|
|
|
<P>
|
|
Open the named file for reading, and return a new input channel
|
|
on that file, positioned at the beginning of the file.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val open_in_bin </I>
|
|
|
|
:
|
|
<B>string -> in_channel</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>open_in</B>
|
|
|
|
, but the file is opened in binary mode,
|
|
so that no translation takes place during reads. On operating
|
|
systems that do not distinguish between text mode and binary
|
|
mode, this function behaves like
|
|
<B>open_in</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val open_in_gen </I>
|
|
|
|
:
|
|
<B>open_flag list -> int -> string -> in_channel</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>open_in_gen mode perm filename</B>
|
|
|
|
opens the named file for reading,
|
|
as described above. The extra arguments
|
|
<B>mode</B>
|
|
|
|
and
|
|
<B>perm</B>
|
|
|
|
specify the opening mode and file permissions.
|
|
<B>open_in</B>
|
|
|
|
and
|
|
<B>open_in_bin</B>
|
|
|
|
are special
|
|
cases of this function.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val input_char </I>
|
|
|
|
:
|
|
<B>in_channel -> char</B>
|
|
|
|
<P>
|
|
Read one character from the given input channel.
|
|
Raise
|
|
<B>End_of_file</B>
|
|
|
|
if there are no more characters to read.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val input_line </I>
|
|
|
|
:
|
|
<B>in_channel -> string</B>
|
|
|
|
<P>
|
|
Read characters from the given input channel, until a
|
|
newline character is encountered. Return the string of
|
|
all characters read, without the newline character at the end.
|
|
Raise
|
|
<B>End_of_file</B>
|
|
|
|
if the end of the file is reached
|
|
at the beginning of line.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val input </I>
|
|
|
|
:
|
|
<B>in_channel -> bytes -> int -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>input ic buf pos len</B>
|
|
|
|
reads up to
|
|
<B>len</B>
|
|
|
|
characters from
|
|
the given channel
|
|
<B>ic</B>
|
|
|
|
, storing them in byte sequence
|
|
<B>buf</B>
|
|
|
|
, starting at
|
|
character number
|
|
<B>pos</B>
|
|
|
|
.
|
|
It returns the actual number of characters read, between 0 and
|
|
<B>len</B>
|
|
|
|
(inclusive).
|
|
A return value of 0 means that the end of file was reached.
|
|
A return value between 0 and
|
|
<B>len</B>
|
|
|
|
exclusive means that
|
|
not all requested
|
|
<B>len</B>
|
|
|
|
characters were read, either because
|
|
no more characters were available at that time, or because
|
|
the implementation found it convenient to do a partial read;
|
|
<B>input</B>
|
|
|
|
must be called again to read the remaining characters,
|
|
if desired. (See also
|
|
<B>really_input</B>
|
|
|
|
for reading
|
|
exactly
|
|
<B>len</B>
|
|
|
|
characters.)
|
|
Exception
|
|
<B>Invalid_argument input</B>
|
|
|
|
is raised if
|
|
<B>pos</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
do not designate a valid range of
|
|
<B>buf</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val really_input </I>
|
|
|
|
:
|
|
<B>in_channel -> bytes -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>really_input ic buf pos len</B>
|
|
|
|
reads
|
|
<B>len</B>
|
|
|
|
characters from channel
|
|
<B>ic</B>
|
|
|
|
,
|
|
storing them in byte sequence
|
|
<B>buf</B>
|
|
|
|
, starting at character number
|
|
<B>pos</B>
|
|
|
|
.
|
|
Raise
|
|
<B>End_of_file</B>
|
|
|
|
if the end of file is reached before
|
|
<B>len</B>
|
|
|
|
characters have been read.
|
|
Raise
|
|
<B>Invalid_argument really_input</B>
|
|
|
|
if
|
|
<B>pos</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
do not designate a valid range of
|
|
<B>buf</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val really_input_string </I>
|
|
|
|
:
|
|
<B>in_channel -> int -> string</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>really_input_string ic len</B>
|
|
|
|
reads
|
|
<B>len</B>
|
|
|
|
characters from channel
|
|
<B>ic</B>
|
|
|
|
and returns them in a new string.
|
|
Raise
|
|
<B>End_of_file</B>
|
|
|
|
if the end of file is reached before
|
|
<B>len</B>
|
|
|
|
characters have been read.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.02.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val input_byte </I>
|
|
|
|
:
|
|
<B>in_channel -> int</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>input_char</B>
|
|
|
|
, but return the 8-bit integer representing
|
|
the character.
|
|
Raise
|
|
<B>End_of_file</B>
|
|
|
|
if an end of file was reached.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val input_binary_int </I>
|
|
|
|
:
|
|
<B>in_channel -> int</B>
|
|
|
|
<P>
|
|
Read an integer encoded in binary format (4 bytes, big-endian)
|
|
from the given input channel. See
|
|
<B>output_binary_int</B>
|
|
|
|
.
|
|
Raise
|
|
<B>End_of_file</B>
|
|
|
|
if an end of file was reached while reading the
|
|
integer.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val input_value </I>
|
|
|
|
:
|
|
<B>in_channel -> 'a</B>
|
|
|
|
<P>
|
|
Read the representation of a structured value, as produced
|
|
by
|
|
<B>output_value</B>
|
|
|
|
, and return the corresponding value.
|
|
This function is identical to
|
|
<B>Marshal.from_channel</B>
|
|
|
|
;
|
|
see the description of module
|
|
<B>Marshal</B>
|
|
|
|
for more information,
|
|
in particular concerning the lack of type safety.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val seek_in </I>
|
|
|
|
:
|
|
<B>in_channel -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>seek_in chan pos</B>
|
|
|
|
sets the current reading position to
|
|
<B>pos</B>
|
|
|
|
for channel
|
|
<B>chan</B>
|
|
|
|
. This works only for regular files. On
|
|
files of other kinds, the behavior is unspecified.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val pos_in </I>
|
|
|
|
:
|
|
<B>in_channel -> int</B>
|
|
|
|
<P>
|
|
Return the current reading position for the given channel.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val in_channel_length </I>
|
|
|
|
:
|
|
<B>in_channel -> int</B>
|
|
|
|
<P>
|
|
Return the size (number of characters) of the regular file
|
|
on which the given channel is opened. If the channel is opened
|
|
on a file that is not a regular file, the result is meaningless.
|
|
The returned size does not take into account the end-of-line
|
|
translations that can be performed when reading from a channel
|
|
opened in text mode.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val close_in </I>
|
|
|
|
:
|
|
<B>in_channel -> unit</B>
|
|
|
|
<P>
|
|
Close the given channel. Input functions raise a
|
|
<B>Sys_error</B>
|
|
|
|
exception when they are applied to a closed input channel,
|
|
except
|
|
<B>close_in</B>
|
|
|
|
, which does nothing when applied to an already
|
|
closed channel.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val close_in_noerr </I>
|
|
|
|
:
|
|
<B>in_channel -> unit</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>close_in</B>
|
|
|
|
, but ignore all errors.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_binary_mode_in </I>
|
|
|
|
:
|
|
<B>in_channel -> bool -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>set_binary_mode_in ic true</B>
|
|
|
|
sets the channel
|
|
<B>ic</B>
|
|
|
|
to binary
|
|
mode: no translations take place during input.
|
|
<B>set_binary_mode_out ic false</B>
|
|
|
|
sets the channel
|
|
<B>ic</B>
|
|
|
|
to text
|
|
mode: depending on the operating system, some translations
|
|
may take place during input. For instance, under Windows,
|
|
end-of-lines will be translated from
|
|
<B>\r\n</B>
|
|
|
|
to
|
|
<B>\n</B>
|
|
|
|
.
|
|
This function has no effect under operating systems that
|
|
do not distinguish between text mode and binary mode.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAY"> </A>
|
|
<H3>Operations on large files</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<I>module LargeFile : </I>
|
|
|
|
<B>sig end</B>
|
|
|
|
<P>
|
|
<P>
|
|
Operations on large files.
|
|
This sub-module provides 64-bit variants of the channel functions
|
|
that manipulate file positions and file sizes. By representing
|
|
positions and sizes by 64-bit integers (type
|
|
<B>int64</B>
|
|
|
|
) instead of
|
|
regular integers (type
|
|
<B>int</B>
|
|
|
|
), these alternate functions allow
|
|
operating on files whose sizes are greater than
|
|
<B>max_int</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAZ"> </A>
|
|
<H3>References</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<I>type </I>
|
|
|
|
<B>'a</B>
|
|
|
|
<I>ref </I>
|
|
|
|
= {
|
|
<P>
|
|
<B>mutable </B>
|
|
|
|
contents :
|
|
<B>'a</B>
|
|
|
|
;
|
|
<BR> }
|
|
<P>
|
|
<P>
|
|
The type of references (mutable indirection cells) containing
|
|
a value of type
|
|
<B>'a</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val ref </I>
|
|
|
|
:
|
|
<B>'a -> 'a ref</B>
|
|
|
|
<P>
|
|
Return a fresh reference containing the given value.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (!) </I>
|
|
|
|
:
|
|
<B>'a ref -> 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>!r</B>
|
|
|
|
returns the current contents of reference
|
|
<B>r</B>
|
|
|
|
.
|
|
Equivalent to
|
|
<B>fun r -> r.contents</B>
|
|
|
|
.
|
|
Unary operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (:=) </I>
|
|
|
|
:
|
|
<B>'a ref -> 'a -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>r := a</B>
|
|
|
|
stores the value of
|
|
<B>a</B>
|
|
|
|
in reference
|
|
<B>r</B>
|
|
|
|
.
|
|
Equivalent to
|
|
<B>fun r v -> r.contents <- v</B>
|
|
|
|
.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val incr </I>
|
|
|
|
:
|
|
<B>int ref -> unit</B>
|
|
|
|
<P>
|
|
Increment the integer contained in the given reference.
|
|
Equivalent to
|
|
<B>fun r -> r := succ !r</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val decr </I>
|
|
|
|
:
|
|
<B>int ref -> unit</B>
|
|
|
|
<P>
|
|
Decrement the integer contained in the given reference.
|
|
Equivalent to
|
|
<B>fun r -> r := pred !r</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbBA"> </A>
|
|
<H3>Result type</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<I>type </I>
|
|
|
|
<B>('a, 'b)</B>
|
|
|
|
<I>result </I>
|
|
|
|
=
|
|
<BR> | Ok
|
|
<B>of </B>
|
|
|
|
<B>'a</B>
|
|
|
|
<BR> | Error
|
|
<B>of </B>
|
|
|
|
<B>'b</B>
|
|
|
|
<BR>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.03.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbBB"> </A>
|
|
<H3>Operations on format strings</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
Format strings are character strings with special lexical conventions
|
|
that defines the functionality of formatted input/output functions. Format
|
|
strings are used to read data with formatted input functions from module
|
|
<B>Scanf</B>
|
|
|
|
and to print data with formatted output functions from modules
|
|
<B>Printf</B>
|
|
|
|
and
|
|
<B>Format</B>
|
|
|
|
.
|
|
<P>
|
|
Format strings are made of three kinds of entities:
|
|
<P>
|
|
-conversions specifications, introduced by the special character
|
|
<B>'%'</B>
|
|
|
|
followed by one or more characters specifying what kind of argument to
|
|
read or print,
|
|
<P>
|
|
-formatting indications, introduced by the special character
|
|
<B>'@'</B>
|
|
|
|
followed by one or more characters specifying how to read or print the
|
|
argument,
|
|
<P>
|
|
-plain characters that are regular characters with usual lexical
|
|
conventions. Plain characters specify string literals to be read in the
|
|
input or printed in the output.
|
|
<P>
|
|
There is an additional lexical rule to escape the special characters
|
|
<B>'%'</B>
|
|
|
|
and
|
|
<B>'@'</B>
|
|
|
|
in format strings: if a special character follows a
|
|
<B>'%'</B>
|
|
|
|
character, it is treated as a plain character. In other words,
|
|
<B>%%</B>
|
|
|
|
is
|
|
considered as a plain
|
|
<B>'%'</B>
|
|
|
|
and
|
|
<B>%@</B>
|
|
|
|
as a plain
|
|
<B>'@'</B>
|
|
|
|
.
|
|
<P>
|
|
For more information about conversion specifications and formatting
|
|
indications available, read the documentation of modules
|
|
<B>Scanf</B>
|
|
|
|
,
|
|
<B>Printf</B>
|
|
|
|
and
|
|
<B>Format</B>
|
|
|
|
.
|
|
<P>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
Format strings have a general and highly polymorphic type
|
|
<B>('a, 'b, 'c, 'd, 'e, 'f) format6</B>
|
|
|
|
.
|
|
The two simplified types,
|
|
<B>format</B>
|
|
|
|
and
|
|
<B>format4</B>
|
|
|
|
below are
|
|
included for backward compatibility with earlier releases of
|
|
OCaml.
|
|
<P>
|
|
The meaning of format string type parameters is as follows:
|
|
<P>
|
|
<P>
|
|
-
|
|
<B>'a</B>
|
|
|
|
is the type of the parameters of the format for formatted output
|
|
functions (
|
|
<B>printf</B>
|
|
|
|
-style functions);
|
|
<B>'a</B>
|
|
|
|
is the type of the values read by the format for formatted input
|
|
functions (
|
|
<B>scanf</B>
|
|
|
|
-style functions).
|
|
<P>
|
|
<P>
|
|
-
|
|
<B>'b</B>
|
|
|
|
is the type of input source for formatted input functions and the
|
|
type of output target for formatted output functions.
|
|
For
|
|
<B>printf</B>
|
|
|
|
-style functions from module
|
|
<B>Printf</B>
|
|
|
|
,
|
|
<B>'b</B>
|
|
|
|
is typically
|
|
<B>out_channel</B>
|
|
|
|
;
|
|
for
|
|
<B>printf</B>
|
|
|
|
-style functions from module
|
|
<B>Format</B>
|
|
|
|
,
|
|
<B>'b</B>
|
|
|
|
is typically
|
|
<B>Format.formatter</B>
|
|
|
|
;
|
|
for
|
|
<B>scanf</B>
|
|
|
|
-style functions from module
|
|
<B>Scanf</B>
|
|
|
|
,
|
|
<B>'b</B>
|
|
|
|
is typically
|
|
<B>Scanf.Scanning.in_channel</B>
|
|
|
|
.
|
|
<P>
|
|
Type argument
|
|
<B>'b</B>
|
|
|
|
is also the type of the first argument given to
|
|
user's defined printing functions for
|
|
<B>%a</B>
|
|
|
|
and
|
|
<B>%t</B>
|
|
|
|
conversions,
|
|
and user's defined reading functions for
|
|
<B>%r</B>
|
|
|
|
conversion.
|
|
<P>
|
|
<P>
|
|
-
|
|
<B>'c</B>
|
|
|
|
is the type of the result of the
|
|
<B>%a</B>
|
|
|
|
and
|
|
<B>%t</B>
|
|
|
|
printing
|
|
functions, and also the type of the argument transmitted to the
|
|
first argument of
|
|
<B>kprintf</B>
|
|
|
|
-style functions or to the
|
|
<B>kscanf</B>
|
|
|
|
-style functions.
|
|
<P>
|
|
<P>
|
|
-
|
|
<B>'d</B>
|
|
|
|
is the type of parameters for the
|
|
<B>scanf</B>
|
|
|
|
-style functions.
|
|
<P>
|
|
<P>
|
|
-
|
|
<B>'e</B>
|
|
|
|
is the type of the receiver function for the
|
|
<B>scanf</B>
|
|
|
|
-style functions.
|
|
<P>
|
|
<P>
|
|
-
|
|
<B>'f</B>
|
|
|
|
is the final result type of a formatted input/output function
|
|
invocation: for the
|
|
<B>printf</B>
|
|
|
|
-style functions, it is typically
|
|
<B>unit</B>
|
|
|
|
;
|
|
for the
|
|
<B>scanf</B>
|
|
|
|
-style functions, it is typically the result type of the
|
|
receiver function.
|
|
<P>
|
|
<P>
|
|
|
|
<I>type </I>
|
|
|
|
<B>('a, 'b, 'c, 'd, 'e, 'f)</B>
|
|
|
|
<I>format6 </I>
|
|
|
|
=
|
|
<B>('a, 'b, 'c, 'd, 'e, 'f) CamlinternalFormatBasics.format6</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>type </I>
|
|
|
|
<B>('a, 'b, 'c, 'd)</B>
|
|
|
|
<I>format4 </I>
|
|
|
|
=
|
|
<B>('a, 'b, 'c, 'c, 'c, 'd) format6</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>type </I>
|
|
|
|
<B>('a, 'b, 'c)</B>
|
|
|
|
<I>format </I>
|
|
|
|
=
|
|
<B>('a, 'b, 'c, 'c) format4</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val string_of_format </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c, 'd, 'e, 'f) format6 -> string</B>
|
|
|
|
<P>
|
|
Converts a format string into a string.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val format_of_string </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c, 'd, 'e, 'f) format6 -></B>
|
|
|
|
<B>('a, 'b, 'c, 'd, 'e, 'f) format6</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>format_of_string s</B>
|
|
|
|
returns a format string read from the string
|
|
literal
|
|
<B>s</B>
|
|
|
|
.
|
|
Note:
|
|
<B>format_of_string</B>
|
|
|
|
can not convert a string argument that is not a
|
|
literal. If you need this functionality, use the more general
|
|
<B>Scanf.format_from_string</B>
|
|
|
|
function.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val (^^) </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c, 'd, 'e, 'f) format6 -></B>
|
|
|
|
<B>('f, 'b, 'c, 'e, 'g, 'h) format6 -></B>
|
|
|
|
<B>('a, 'b, 'c, 'd, 'g, 'h) format6</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>f1 ^^ f2</B>
|
|
|
|
catenates format strings
|
|
<B>f1</B>
|
|
|
|
and
|
|
<B>f2</B>
|
|
|
|
. The result is a
|
|
format string that behaves as the concatenation of format strings
|
|
<B>f1</B>
|
|
|
|
and
|
|
<B>f2</B>
|
|
|
|
: in case of formatted output, it accepts arguments from
|
|
<B>f1</B>
|
|
|
|
, then
|
|
arguments from
|
|
<B>f2</B>
|
|
|
|
; in case of formatted input, it returns results from
|
|
<B>f1</B>
|
|
|
|
, then results from
|
|
<B>f2</B>
|
|
|
|
.
|
|
Right-associative operator, see
|
|
<B>Ocaml_operators</B>
|
|
|
|
for more information.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbBC"> </A>
|
|
<H3>Program termination</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val exit </I>
|
|
|
|
:
|
|
<B>int -> 'a</B>
|
|
|
|
<P>
|
|
Terminate the process, returning the given status code
|
|
to the operating system: usually 0 to indicate no errors,
|
|
and a small positive integer to indicate failure.
|
|
All open output channels are flushed with
|
|
<B>flush_all</B>
|
|
|
|
.
|
|
An implicit
|
|
<B>exit 0</B>
|
|
|
|
is performed each time a program
|
|
terminates normally. An implicit
|
|
<B>exit 2</B>
|
|
|
|
is performed if the program
|
|
terminates early because of an uncaught exception.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val at_exit </I>
|
|
|
|
:
|
|
<B>(unit -> unit) -> unit</B>
|
|
|
|
<P>
|
|
Register the given function to be called at program termination
|
|
time. The functions registered with
|
|
<B>at_exit</B>
|
|
|
|
will be called when
|
|
the program does any of the following:
|
|
<P>
|
|
-executes
|
|
<B>exit</B>
|
|
|
|
<P>
|
|
<P>
|
|
-terminates, either normally or because of an uncaught
|
|
exception
|
|
<P>
|
|
-executes the C function
|
|
<B>caml_shutdown</B>
|
|
|
|
.
|
|
The functions are called in 'last in, first out' order: the
|
|
function most recently added with
|
|
<B>at_exit</B>
|
|
|
|
is called first.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbBD"> </A>
|
|
<H3>Standard library modules </H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<I>module Arg : </I>
|
|
|
|
<B>(module Stdlib__arg)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Array : </I>
|
|
|
|
<B>(module Stdlib__array)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module ArrayLabels : </I>
|
|
|
|
<B>(module Stdlib__arrayLabels)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Bigarray : </I>
|
|
|
|
<B>(module Stdlib__bigarray)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Bool : </I>
|
|
|
|
<B>(module Stdlib__bool)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Buffer : </I>
|
|
|
|
<B>(module Stdlib__buffer)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Bytes : </I>
|
|
|
|
<B>(module Stdlib__bytes)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module BytesLabels : </I>
|
|
|
|
<B>(module Stdlib__bytesLabels)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Callback : </I>
|
|
|
|
<B>(module Stdlib__callback)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Char : </I>
|
|
|
|
<B>(module Stdlib__char)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Complex : </I>
|
|
|
|
<B>(module Stdlib__complex)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Digest : </I>
|
|
|
|
<B>(module Stdlib__digest)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Ephemeron : </I>
|
|
|
|
<B>(module Stdlib__ephemeron)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Filename : </I>
|
|
|
|
<B>(module Stdlib__filename)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Float : </I>
|
|
|
|
<B>(module Stdlib__float)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Format : </I>
|
|
|
|
<B>(module Stdlib__format)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Fun : </I>
|
|
|
|
<B>(module Stdlib__fun)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Gc : </I>
|
|
|
|
<B>(module Stdlib__gc)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Genlex : </I>
|
|
|
|
<B>(module Stdlib__genlex)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Hashtbl : </I>
|
|
|
|
<B>(module Stdlib__hashtbl)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Int : </I>
|
|
|
|
<B>(module Stdlib__int)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Int32 : </I>
|
|
|
|
<B>(module Stdlib__int32)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Int64 : </I>
|
|
|
|
<B>(module Stdlib__int64)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Lazy : </I>
|
|
|
|
<B>(module Stdlib__lazy)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Lexing : </I>
|
|
|
|
<B>(module Stdlib__lexing)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module List : </I>
|
|
|
|
<B>(module Stdlib__list)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module ListLabels : </I>
|
|
|
|
<B>(module Stdlib__listLabels)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Map : </I>
|
|
|
|
<B>(module Stdlib__map)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Marshal : </I>
|
|
|
|
<B>(module Stdlib__marshal)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module MoreLabels : </I>
|
|
|
|
<B>(module Stdlib__moreLabels)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Nativeint : </I>
|
|
|
|
<B>(module Stdlib__nativeint)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Obj : </I>
|
|
|
|
<B>(module Stdlib__obj)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Oo : </I>
|
|
|
|
<B>(module Stdlib__oo)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Option : </I>
|
|
|
|
<B>(module Stdlib__option)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Parsing : </I>
|
|
|
|
<B>(module Stdlib__parsing)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Pervasives : </I>
|
|
|
|
<B>(module Stdlib__pervasives)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Printexc : </I>
|
|
|
|
<B>(module Stdlib__printexc)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Printf : </I>
|
|
|
|
<B>(module Stdlib__printf)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Queue : </I>
|
|
|
|
<B>(module Stdlib__queue)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Random : </I>
|
|
|
|
<B>(module Stdlib__random)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Result : </I>
|
|
|
|
<B>(module Stdlib__result)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Scanf : </I>
|
|
|
|
<B>(module Stdlib__scanf)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Seq : </I>
|
|
|
|
<B>(module Stdlib__seq)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Set : </I>
|
|
|
|
<B>(module Stdlib__set)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Spacetime : </I>
|
|
|
|
<B>(module Stdlib__spacetime)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Stack : </I>
|
|
|
|
<B>(module Stdlib__stack)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module StdLabels : </I>
|
|
|
|
<B>(module Stdlib__stdLabels)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Stream : </I>
|
|
|
|
<B>(module Stdlib__stream)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module String : </I>
|
|
|
|
<B>(module Stdlib__string)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module StringLabels : </I>
|
|
|
|
<B>(module Stdlib__stringLabels)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Sys : </I>
|
|
|
|
<B>(module Stdlib__sys)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Uchar : </I>
|
|
|
|
<B>(module Stdlib__uchar)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Unit : </I>
|
|
|
|
<B>(module Stdlib__unit)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>module Weak : </I>
|
|
|
|
<B>(module Stdlib__weak)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">Module</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAE">Exceptions</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">Comparisons</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">Boolean operations</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">Debugging</A><DD>
|
|
<DT id="8"><A HREF="#lbAI">Composition operators</A><DD>
|
|
<DT id="9"><A HREF="#lbAJ">Integer arithmetic</A><DD>
|
|
<DT id="10"><A HREF="#lbAK">Bitwise operations</A><DD>
|
|
<DT id="11"><A HREF="#lbAL">Floating-point arithmetic</A><DD>
|
|
<DT id="12"><A HREF="#lbAM">String operations</A><DD>
|
|
<DT id="13"><A HREF="#lbAN">Character operations</A><DD>
|
|
<DT id="14"><A HREF="#lbAO">Unit operations</A><DD>
|
|
<DT id="15"><A HREF="#lbAP">String conversion functions</A><DD>
|
|
<DT id="16"><A HREF="#lbAQ">Pair operations</A><DD>
|
|
<DT id="17"><A HREF="#lbAR">List operations</A><DD>
|
|
<DT id="18"><A HREF="#lbAS">Input/output</A><DD>
|
|
<DT id="19"><A HREF="#lbAT">Output functions on standard output</A><DD>
|
|
<DT id="20"><A HREF="#lbAU">Output functions on standard error</A><DD>
|
|
<DT id="21"><A HREF="#lbAV">Input functions on standard input</A><DD>
|
|
<DT id="22"><A HREF="#lbAW">General output functions</A><DD>
|
|
<DT id="23"><A HREF="#lbAX">General input functions</A><DD>
|
|
<DT id="24"><A HREF="#lbAY">Operations on large files</A><DD>
|
|
<DT id="25"><A HREF="#lbAZ">References</A><DD>
|
|
<DT id="26"><A HREF="#lbBA">Result type</A><DD>
|
|
<DT id="27"><A HREF="#lbBB">Operations on format strings</A><DD>
|
|
<DT id="28"><A HREF="#lbBC">Program termination</A><DD>
|
|
<DT id="29"><A HREF="#lbBD">Standard library modules </A><DD>
|
|
</DL>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:57 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|