package monomorphic

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
module Stdlib : sig ... end
include module type of Stdlib
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

exception Exit

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 Not_found

Exception raised by search functions when the desired object could not be found.

exception Out_of_memory

Exception raised by the garbage collector when there is insufficient memory to complete the computation. (Not reliable for allocations on the minor heap.)

exception Stack_overflow

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 End_of_file

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.

exception Sys_blocked_io

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.

  • since 4.12.0

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.

  • since 4.13.0
val asinh : float -> float

Hyperbolic arc sine. The argument and result range over the entire real line. Result is in radians.

  • since 4.13.0
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.

  • since 4.13.0

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.

Input/output

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

Input functions on standard input

General output functions

General input functions

Operations on large files

References

Result type

Operations on format strings

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

module Arg : sig ... end

Parsing of command line arguments.

module Array : sig ... end

Array operations.

module ArrayLabels : sig ... end

Array operations.

module Atomic : sig ... end

This module provides a purely sequential implementation of the concurrent atomic references provided by the Multicore OCaml standard library:

module Bigarray : sig ... end

Large, multi-dimensional, numerical arrays.

module Bool : sig ... end

Boolean values.

module Buffer : sig ... end

Extensible buffers.

module Bytes : sig ... end

Byte sequence operations.

module BytesLabels : sig ... end

Byte sequence operations.

module Callback : sig ... end

Registering OCaml values with the C runtime.

module Char : sig ... end

Character operations.

module Complex : sig ... end

Complex numbers.

module Digest : sig ... end

MD5 message digest.

module Either : sig ... end

Either type.

module Ephemeron : sig ... end

Ephemerons and weak hash tables.

module Filename : sig ... end

Operations on file names.

module Float : sig ... end

Floating-point arithmetic.

module Format : sig ... end

Pretty-printing.

module Fun : sig ... end

Function manipulation.

module Gc : sig ... end

Memory management control and statistics; finalised values.

module Genlex : sig ... end
module Hashtbl : sig ... end

Hash tables and hash functions.

module In_channel : sig ... end

Input channels.

module Int : sig ... end

Integer values.

module Int32 : sig ... end

32-bit integers.

module Int64 : sig ... end

64-bit integers.

module Lazy : sig ... end

Deferred computations.

module Lexing : sig ... end

The run-time library for lexers generated by ocamllex.

module Map : sig ... end

Association tables over ordered types.

module Marshal : sig ... end

Marshaling of data structures.

module MoreLabels : sig ... end

Extra labeled libraries.

module Nativeint : sig ... end

Processor-native integers.

module Obj : sig ... end

Operations on internal representations of values.

module Oo : sig ... end

Operations on objects

module Option : sig ... end

Option values.

module Out_channel : sig ... end

Output channels.

module Parsing : sig ... end

The run-time library for parsers generated by ocamlyacc.

module Printexc : sig ... end

Facilities for printing exceptions and inspecting current call stack.

module Printf : sig ... end

Formatted output functions.

module Queue : sig ... end

First-in first-out queues.

module Random : sig ... end

Pseudo-random number generators (PRNG).

module Result : sig ... end

Result values.

module Scanf : sig ... end

Formatted input functions.

module Seq : sig ... end

Sequences.

module Set : sig ... end

Sets over ordered types.

module Stack : sig ... end

Last-in first-out stacks.

module Stream : sig ... end
module String : sig ... end

Strings.

module StringLabels : sig ... end

Strings.

module Sys : sig ... end

System interface.

module Uchar : sig ... end

Unicode characters.

module Unit : sig ... end

Unit values.

module Weak : sig ... end

Arrays of weak pointers and hash sets of weak pointers.

module List : sig ... end
module ListLabels : sig ... end
module StdLabels : sig ... end
module Pervasives : sig ... end
include module type of Pervasives
include module type of Pervasives
  • deprecated Use Stdlib instead. If you need to stay compatible with OCaml < 4.07, you can use the stdlib-shims library: https://github.com/ocaml/stdlib-shims
val raise : exn -> 'a
val raise_notrace : exn -> 'a
val invalid_arg : string -> 'a
val failwith : string -> 'a
exception Exit
val (=) : 'a -> 'a -> bool
val (<>) : 'a -> 'a -> bool
val (<) : 'a -> 'a -> bool
val (>) : 'a -> 'a -> bool
val (<=) : 'a -> 'a -> bool
val (>=) : 'a -> 'a -> bool
val (==) : 'a -> 'a -> bool
val (!=) : 'a -> 'a -> bool
val not : bool -> bool
val (&&) : bool -> bool -> bool
val (&) : bool -> bool -> bool
  • deprecated Use (&&) instead.
val (||) : bool -> bool -> bool
val or : bool -> bool -> bool
  • deprecated Use (||) instead.
val __LOC__ : string
val __FILE__ : string
val __LINE__ : int
val __MODULE__ : string
val __POS__ : string * int * int * int
val __LOC_OF__ : 'a -> string * 'a
val __LINE_OF__ : 'a -> int * 'a
val __POS_OF__ : 'a -> (string * int * int * int) * 'a
val (|>) : 'a -> ('a -> 'b) -> 'b
val (@@) : ('a -> 'b) -> 'a -> 'b
val (~-) : int -> int
val (~+) : int -> int
val (+) : int -> int -> int
val (-) : int -> int -> int
val (*) : int -> int -> int
val (/) : int -> int -> int
val (mod) : int -> int -> int
val (land) : int -> int -> int
val (lor) : int -> int -> int
val (lxor) : int -> int -> int
val lnot : int -> int
val (lsl) : int -> int -> int
val (lsr) : int -> int -> int
val (asr) : int -> int -> int
val (~-.) : float -> float
val (~+.) : float -> float
val (+.) : float -> float -> float
val (-.) : float -> float -> float
val (*.) : float -> float -> float
val (/.) : float -> float -> float
val (**) : float -> float -> float
val sqrt : float -> float
val exp : float -> float
val log : float -> float
val log10 : float -> float
val expm1 : float -> float
val log1p : float -> float
val cos : float -> float
val sin : float -> float
val tan : float -> float
val acos : float -> float
val asin : float -> float
val atan : float -> float
val atan2 : float -> float -> float
val hypot : float -> float -> float
val cosh : float -> float
val sinh : float -> float
val tanh : float -> float
val ceil : float -> float
val floor : float -> float
val abs_float : float -> float
val copysign : float -> float -> float
val mod_float : float -> float -> float
val frexp : float -> float * int
val ldexp : float -> int -> float
val modf : float -> float * float
val float : int -> float
val float_of_int : int -> float
val truncate : float -> int
val int_of_float : float -> int
val infinity : float
val neg_infinity : float
val nan : float
val max_float : float
val min_float : float
val epsilon_float : float
type nonrec fpclass = fpclass =
  1. | FP_normal
  2. | FP_subnormal
  3. | FP_zero
  4. | FP_infinite
  5. | FP_nan
val classify_float : float -> fpclass
val (^) : string -> string -> string
val int_of_char : char -> int
val char_of_int : int -> char
val ignore : 'a -> unit
val string_of_bool : bool -> string
val bool_of_string : string -> bool
val bool_of_string_opt : string -> bool option
val string_of_int : int -> string
val int_of_string : string -> int
val int_of_string_opt : string -> int option
val string_of_float : float -> string
val float_of_string : string -> float
val float_of_string_opt : string -> float option
val fst : ('a * 'b) -> 'a
val snd : ('a * 'b) -> 'b
val (@) : 'a list -> 'a list -> 'a list
type nonrec in_channel = in_channel
type nonrec out_channel = out_channel
val stdin : in_channel
val stdout : out_channel
val stderr : out_channel
val print_char : char -> unit
val print_string : string -> unit
val print_bytes : bytes -> unit
val print_int : int -> unit
val print_float : float -> unit
val print_endline : string -> unit
val print_newline : unit -> unit
val prerr_char : char -> unit
val prerr_string : string -> unit
val prerr_bytes : bytes -> unit
val prerr_int : int -> unit
val prerr_float : float -> unit
val prerr_endline : string -> unit
val prerr_newline : unit -> unit
val read_line : unit -> string
val read_int : unit -> int
val read_int_opt : unit -> int option
val read_float : unit -> float
val read_float_opt : unit -> float option
type nonrec open_flag = open_flag =
  1. | Open_rdonly
  2. | Open_wronly
  3. | Open_append
  4. | Open_creat
  5. | Open_trunc
  6. | Open_excl
  7. | Open_binary
  8. | Open_text
  9. | Open_nonblock
val open_out : string -> out_channel
val open_out_bin : string -> out_channel
val open_out_gen : open_flag list -> int -> string -> out_channel
val flush : out_channel -> unit
val flush_all : unit -> unit
val output_char : out_channel -> char -> unit
val output_string : out_channel -> string -> unit
val output_bytes : out_channel -> bytes -> unit
val output : out_channel -> bytes -> int -> int -> unit
val output_substring : out_channel -> string -> int -> int -> unit
val output_byte : out_channel -> int -> unit
val output_binary_int : out_channel -> int -> unit
val output_value : out_channel -> 'a -> unit
val seek_out : out_channel -> int -> unit
val pos_out : out_channel -> int
val out_channel_length : out_channel -> int
val close_out : out_channel -> unit
val close_out_noerr : out_channel -> unit
val set_binary_mode_out : out_channel -> bool -> unit
val open_in : string -> in_channel
val open_in_bin : string -> in_channel
val open_in_gen : open_flag list -> int -> string -> in_channel
val input_char : in_channel -> char
val input_line : in_channel -> string
val input : in_channel -> bytes -> int -> int -> int
val really_input : in_channel -> bytes -> int -> int -> unit
val really_input_string : in_channel -> int -> string
val input_byte : in_channel -> int
val input_binary_int : in_channel -> int
val input_value : in_channel -> 'a
val seek_in : in_channel -> int -> unit
val pos_in : in_channel -> int
val in_channel_length : in_channel -> int
val close_in : in_channel -> unit
val close_in_noerr : in_channel -> unit
val set_binary_mode_in : in_channel -> bool -> unit
module LargeFile = LargeFile
type nonrec 'a ref = 'a ref = {
  1. mutable contents : 'a;
}
val ref : 'a -> 'a ref
val (!) : 'a ref -> 'a
val (:=) : 'a ref -> 'a -> unit
val incr : int ref -> unit
val decr : int ref -> unit
type nonrec ('a, 'b) result = ('a, 'b) result =
  1. | Ok of 'a
  2. | Error of 'b
type ('a, 'b, 'c, 'd, 'e, 'f) format6 = ('a, 'b, 'c, 'd, 'e, 'f) CamlinternalFormatBasics.format6
type ('a, 'b, 'c, 'd) format4 = ('a, 'b, 'c, 'c, 'c, 'd) format6
type ('a, 'b, 'c) format = ('a, 'b, 'c, 'c) format4
val string_of_format : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> string
val format_of_string : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> ('a, 'b, 'c, 'd, 'e, 'f) format6
val (^^) : ('a, 'b, 'c, 'd, 'e, 'f) format6 -> ('f, 'b, 'c, 'e, 'g, 'h) format6 -> ('a, 'b, 'c, 'd, 'g, 'h) format6
val exit : int -> 'a
val at_exit : (unit -> unit) -> unit
val valid_float_lexem : string -> string
val do_at_exit : unit -> unit
include module type of Int

Integers

type t = int

The type for integer values.

val zero : int

zero is the integer 0.

val one : int

one is the integer 1.

val minus_one : int

minus_one is the integer -1.

val neg : int -> int

neg x is ~-x.

val add : int -> int -> int

add x y is the addition x + y.

val sub : int -> int -> int

sub x y is the subtraction x - y.

val mul : int -> int -> int

mul x y is the multiplication x * y.

val div : int -> int -> int

div x y is the division x / y. See Stdlib.(/) for details.

val rem : int -> int -> int

rem x y is the remainder x mod y. See Stdlib.(mod) for details.

val succ : int -> int

succ x is add x 1.

val pred : int -> int

pred x is sub x 1.

val abs : int -> int

abs x is the absolute value of x. That is x if x is positive and neg x if x is negative. Warning. This may be negative if the argument is min_int.

val max_int : int

max_int is the greatest representable integer, 2{^[Sys.int_size - 1]} - 1.

val min_int : int

min_int is the smallest representable integer, -2{^[Sys.int_size - 1]}.

val logand : int -> int -> int

logand x y is the bitwise logical and of x and y.

val logor : int -> int -> int

logor x y is the bitwise logical or of x and y.

val logxor : int -> int -> int

logxor x y is the bitwise logical exclusive or of x and y.

val lognot : int -> int

lognot x is the bitwise logical negation of x.

val shift_left : int -> int -> int

shift_left x n shifts x to the left by n bits. The result is unspecified if n < 0 or n > Sys.int_size.

val shift_right : int -> int -> int

shift_right x n shifts x to the right by n bits. This is an arithmetic shift: the sign bit of x is replicated and inserted in the vacated bits. The result is unspecified if n < 0 or n > Sys.int_size.

val shift_right_logical : int -> int -> int

shift_right x n shifts x to the right by n bits. This is a logical shift: zeroes are inserted in the vacated bits regardless of the sign of x. The result is unspecified if n < 0 or n > Sys.int_size.

Predicates and comparisons

val equal : int -> int -> bool

equal x y is true if and only if x = y.

val compare : int -> int -> int

compare x y is Stdlib.compare x y but more efficient.

val min : int -> int -> int

Return the smaller of the two arguments.

  • since 4.13.0
val max : int -> int -> int

Return the greater of the two arguments.

  • since 4.13.0

Converting

val to_float : int -> float

to_float x is x as a floating point number.

val of_float : float -> int

of_float x truncates x to an integer. The result is unspecified if the argument is nan or falls outside the range of representable integers.

val to_string : int -> string

to_string x is the written representation of x in decimal.