include module type of Stdlib
with module List := List
and module ListLabels := ListLabels
and module StdLabels := StdLabels
and module Pervasives := Pervasives
and type in_channel := in_channel
and type out_channel := out_channel
Exceptions
The Exit
exception is not raised by any library function. It is provided for use in your programs.
exception Match_failure of string * int * int
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).
exception Assert_failure of string * int * int
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).
exception Invalid_argument of string
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.
exception Failure of string
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).
Exception raised by search functions when the desired object could not be found.
Exception raised by the garbage collector when there is insufficient memory to complete the computation. (Not reliable for allocations on the minor heap.)
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.
Before 4.10, it was not fully implemented by the native-code compiler.
exception Sys_error of string
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).
Exception raised by input functions to signal that the end of file has been reached.
exception Division_by_zero
Exception raised by integer division and remainder operations when their second argument is zero.
A special case of Sys_error raised when no I/O is possible on a non-blocking I/O channel.
exception Undefined_recursive_module of string * int * int
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).
Comparisons
Boolean operations
Debugging
val __FUNCTION__ : string
__FUNCTION__
returns the name of the current function or method, including any enclosing modules or classes.
Composition operators
Integer arithmetic
Integers are Sys.int_size
bits wide. All operations are taken modulo 2Sys.int_size
. They do not fail on overflow.
Bitwise operations
Floating-point arithmetic
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 infinity
for 1.0 /. 0.0
, neg_infinity
for -1.0 /. 0.0
, and nan
('not a number') for 0.0 /. 0.0
. These special numbers then propagate through floating-point computations as expected: for instance, 1.0 /. infinity
is 0.0
, basic arithmetic operations (+.
, -.
, *.
, /.
) with nan
as an argument return nan
, ...
val acosh : float -> float
Hyperbolic arc cosine. The argument must fall within the range [1.0, inf]
. Result is in radians and is between 0.0
and inf
.
val asinh : float -> float
Hyperbolic arc sine. The argument and result range over the entire real line. Result is in radians.
val atanh : float -> float
Hyperbolic arc tangent. The argument must fall within the range [-1.0, 1.0]
. Result is in radians and ranges over the entire real line.
String operations
More string operations are provided in module String
.
Character operations
More character operations are provided in module Char
.
Unit operations
String conversion functions
Pair operations
List operations
More list operations are provided in module List
.
Note: all input/output functions can raise Sys_error
when the system calls they invoke fail.
Output functions on standard output
Output functions on standard error
General output functions
Operations on large files
References
Result type
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 Scanf
and to print data with formatted output functions from modules Printf
and Format
.
Format strings are made of three kinds of entities:
- conversions specifications, introduced by the special character
'%'
followed by one or more characters specifying what kind of argument to read or print, - formatting indications, introduced by the special character
'@'
followed by one or more characters specifying how to read or print the argument, - 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.
There is an additional lexical rule to escape the special characters '%'
and '@'
in format strings: if a special character follows a '%'
character, it is treated as a plain character. In other words, "%%"
is considered as a plain '%'
and "%@"
as a plain '@'
.
For more information about conversion specifications and formatting indications available, read the documentation of modules Scanf
, Printf
and Format
.
Format strings have a general and highly polymorphic type ('a, 'b, 'c, 'd, 'e, 'f) format6
. The two simplified types, format
and format4
below are included for backward compatibility with earlier releases of OCaml.
The meaning of format string type parameters is as follows:
'a
is the type of the parameters of the format for formatted output functions (printf
-style functions); 'a
is the type of the values read by the format for formatted input functions (scanf
-style functions).
'b
is the type of input source for formatted input functions and the type of output target for formatted output functions. For printf
-style functions from module Printf
, 'b
is typically out_channel
; for printf
-style functions from module Format
, 'b
is typically Format.formatter
; for scanf
-style functions from module Scanf
, 'b
is typically Scanf.Scanning.in_channel
.
Type argument 'b
is also the type of the first argument given to user's defined printing functions for %a
and %t
conversions, and user's defined reading functions for %r
conversion.
'c
is the type of the result of the %a
and %t
printing functions, and also the type of the argument transmitted to the first argument of kprintf
-style functions or to the kscanf
-style functions.
'd
is the type of parameters for the scanf
-style functions.
'e
is the type of the receiver function for the scanf
-style functions.
'f
is the final result type of a formatted input/output function invocation: for the printf
-style functions, it is typically unit
; for the scanf
-style functions, it is typically the result type of the receiver function.
Program termination
Standard library modules
Parsing of command line arguments.
module Array : sig ... end
This module provides a purely sequential implementation of the concurrent atomic references provided by the Multicore OCaml standard library:
Large, multi-dimensional, numerical arrays.
module Bool : sig ... end
module Bytes : sig ... end
Byte sequence operations.
Byte sequence operations.
Registering OCaml values with the C runtime.
module Char : sig ... end
Ephemerons and weak hash tables.
Operations on file names.
module Float : sig ... end
Floating-point arithmetic.
Memory management control and statistics; finalised values.
Hash tables and hash functions.
module Int32 : sig ... end
module Int64 : sig ... end
module Lazy : sig ... end
The run-time library for lexers generated by ocamllex
.
Association tables over ordered types.
Marshaling of data structures.
Processor-native integers.
Operations on internal representations of values.
The run-time library for parsers generated by ocamlyacc
.
Facilities for printing exceptions and inspecting current call stack.
Formatted output functions.
module Queue : sig ... end
First-in first-out queues.
Pseudo-random number generators (PRNG).
module Scanf : sig ... end
Formatted input functions.
module Stack : sig ... end
Last-in first-out stacks.
module Uchar : sig ... end
module Unit : sig ... end
module Weak : sig ... end
Arrays of weak pointers and hash sets of weak pointers.