This chapter describes the OCaml core library, which iscomposed of declarations for built-in types and exceptions, plusthe moduleStdlib that provides basic operations on thesebuilt-in types. TheStdlib module is special in twoways:
The following built-in types and predefined exceptions are alwaysdefined in thecompilation environment, but are not part of any module. As aconsequence, they can only be referred by their short names.
type int
The type of integer numbers.
type char
The type of characters.
type bytes
The type of (writable) byte sequences.
type string
The type of (read-only) character strings.
type float
The type of floating-point numbers.
type bool = false | true
The type of booleans (truth values).
type unit = ()
The type of the unit value.
type exn
The type of exception values.
type 'a array
The type of arrays whose elements have type'a.
type 'a list = [] | :: of 'a * 'a list
The type of lists whose elements have type'a.
type 'a option = None | Some of 'a
The type of optional values of type'a.
type int32
The type of signed 32-bit integers.Literals for 32-bit integers are suffixed by l.See theInt32 module.
type int64
The type of signed 64-bit integers.Literals for 64-bit integers are suffixed by L.See theInt64 module.
type nativeint
The type of signed, platform-native integers (32 bits on 32-bitprocessors, 64 bits on 64-bit processors).Literals for native integers are suffixed by n.See theNativeint module.
type ('a, 'b, 'c, 'd, 'e, 'f) format6The type of format strings.'a is the type of the parameters ofthe format,'f is the result type for theprintf-stylefunctions,'b is the type of the first argument given to%a and%t printing functions (see modulePrintf),'c is the result type of these functions, and also the type of theargument transmitted to the first argument ofkprintf-stylefunctions,'d is the result type for thescanf-style functions(see moduleScanf), and'e is the type of the receiver functionfor thescanf-style functions.
type 'a lazy_t
This type is used to implement theLazy module.It should not be used directly.
exception Match_failure of (string * int * int)
Exception raised when none of the cases of a pattern-matchingapply. The arguments are the location of thematch keywordin the source code (file name, line number, column number).
exception Assert_failure of (string * int * int)
Exception raised when an assertion fails. The arguments arethe location of theassert 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 givenarguments do not make sense. The string gives some informationto the programmer. As a general rule, this exception should notbe caught, it denotes a programming error and the code should bemodified not to trigger it.
exception Failure of string
Exception raised by library functions to signal that they areundefined on the given arguments. The string is meant to give someinformation to the programmer; you mustnot pattern match onthe string literal because it may change in future versions (useFailure _ instead).exception Not_found
Exception raised by search functions when the desired objectcould not be found.
exception Out_of_memory
Exception raised by the garbage collector when there isinsufficient memory to complete the computation. (Not reliable forallocations on the minor heap.)
exception Stack_overflow
Exception raised by the bytecode interpreter when the evaluationstack reaches its maximal size. This often indicates infinite orexcessively deep recursion in the user’s program. Before 4.10, itwas not fully implemented by the native-code compiler.
exception Sys_error of string
Exception raised by the input/output functions to report anoperating system error. The string is meant to give someinformation to the programmer; you mustnot pattern match onthe string literal because it may change in future versions (useSys_error _ instead).exception End_of_file
Exception raised by input functions to signal that theend of file has been reached.
exception Division_by_zero
Exception raised by integer division and remainder operationswhen their second argument is zero.
exception Sys_blocked_io
A special case ofSys_error raised when no I/O is possibleon a non-blocking I/O channel.
exception Undefined_recursive_module of (string * int * int)
Exception raised when an ill-founded recursive module definitionis evaluated. (See section 12.2.)The arguments are the location of the definition in the source code(file name, line number, column number).