Module BaseSource

This module is the toplevel of the Base library; it's what you get when you write open Base.

The goal of Base is both to be a more complete standard library, with richer APIs, and to be more consistent in its design. For instance, in the standard library some things have modules and others don't; in Base, everything is a module.

Base extends some modules and data structures from the standard library, like Array, Buffer, Bytes, Char, Hashtbl, Int32, Int64, Lazy, List, Map, Nativeint, Printf, Random, Set, String, Sys, and Uchar. One key difference is that Base doesn't use exceptions as much as the standard library and instead makes heavy use of the Result type, as in:

type ('a,'b) result = Ok of 'a | Error of 'b 

Base also adds entirely new modules, most notably:

Sourcemodule Applicative : sig ... end
Sourcemodule Array : sig ... end

Fixed-length, mutable vector of elements with O(1) get and set operations.

Sourcemodule Avltree : sig ... end

A low-level, mutable AVL tree.

Sourcemodule Backtrace : sig ... end

Module for managing stack backtraces.

Functions for performing binary searches over ordered sequences given length and get functions.

Sourcemodule Binary_searchable : sig ... end
Sourcemodule Blit : sig ... end
Sourcemodule Bool : sig ... end

Boolean type extended to be enumerable, hashable, sexpable, comparable, and stringable.

Sourcemodule Buffer : sig ... end

Extensible character buffers.

Sourcemodule Bytes : sig ... end

OCaml's byte sequence type, semantically similar to a char array, but taking less space in memory.

Sourcemodule Char : sig ... end

A type for 8-bit characters.

Sourcemodule Comparable : sig ... end

Defines functors for making modules comparable.

Sourcemodule Comparator : sig ... end

Comparison and serialization for a type, using a witness type to distinguish between comparison functions with different behavior.

Sourcemodule Comparisons : sig ... end

Interfaces for infix comparison operators and comparison functions.

Sourcemodule Container : sig ... end
Sourcemodule Either : sig ... end
Sourcemodule Equal : sig ... end

This module defines signatures that are to be included in other signatures to ensure a consistent interface to equal functions. There is a signature (S, S1, S2, S3) for each arity of type. Usage looks like:

Sourcemodule Error : sig ... end

A lazy string, implemented with Info, but intended specifically for error messages.

Sourcemodule Exn : sig ... end

Exceptions.

Sourcemodule Field : sig ... end

OCaml record field.

Sourcemodule Float : sig ... end

Floating-point representation and utilities.

Sourcemodule Floatable : sig ... end

Module type with float conversion functions.

Sourcemodule Fn : sig ... end

Various combinators for functions.

Sourcemodule Formatter : sig ... end

The Format.formatter type from OCaml's standard library, exported here for convenience and compatibility with other libraries.

Sourcemodule Hash : sig ... end
Sourcemodule Hash_set : sig ... end
Sourcemodule Hashable : sig ... end
Sourcemodule Hasher : sig ... end

Signatures required of types which can be used in [@@deriving hash].

Sourcemodule Hashtbl : sig ... end

A hash table is a mutable data structure implementing a map between keys and values. It supports constant-time lookup and in-place modification.

Sourcemodule Identifiable : sig ... end
Sourcemodule Indexed_container : sig ... end

Provides generic signatures for containers that support indexed iteration (iteri, foldi, ...). In principle, any container that has iter can also implement iteri, but the idea is that Indexed_container_intf should be included only for containers that have a meaningful underlying ordering.

Sourcemodule Info : sig ... end
Sourcemodule Int : sig ... end
Sourcemodule Int_conversions : sig ... end

Conversions between various integer types

Sourcemodule Int32 : sig ... end

An int of exactly 32 bits, regardless of the machine.

Sourcemodule Int63 : sig ... end

63-bit integers.

Sourcemodule Int64 : sig ... end

64-bit integers.

Sourcemodule Intable : sig ... end

Functor that adds integer conversion functions to a module.

Sourcemodule Int_math : sig ... end

This module implements derived integer operations (e.g., modulo, rounding to multiples) based on other basic operations.

Sourcemodule Invariant : sig ... end

This module defines signatures that are to be included in other signatures to ensure a consistent interface to invariant-style functions. There is a signature (S, S1, S2, S3) for each arity of type. Usage looks like:

Sourcemodule Lazy : sig ... end

A value of type 'a Lazy.t is a deferred computation, called a suspension, that has a result of type 'a.

Sourcemodule List : sig ... end

Immutable, singly-linked lists, giving fast access to the front of the list, and slow (i.e., O(n)) access to the back of the list. The comparison functions on lists are lexicographic.

Sourcemodule Map : sig ... end

Map is a functional data structure (balanced binary tree) implementing finite maps over a totally-ordered domain, called a "key".

Sourcemodule Maybe_bound : sig ... end

Used for specifying a bound (either upper or lower) as inclusive, exclusive, or unbounded.

Sourcemodule Monad : sig ... end

A monad is an abstraction of the concept of sequencing of computations. A value of type 'a monad represents a computation that returns a value of type 'a.

Sourcemodule Nativeint : sig ... end

Processor-native integers.

Sourcemodule Nothing : sig ... end

An uninhabited type. This is useful when interfaces require that a type be specified, but the implementer knows this type will not be used in their implementation of the interface.

Sourcemodule Option : sig ... end

The option type indicates whether a meaningful value is present. It is frequently used to represent success or failure, using None for failure. To be more descriptive about why a function failed, see the Or_error module.

Sourcemodule Option_array : sig ... end

'a Option_array.t is a compact representation of 'a option array: it avoids allocating heap objects representing Some x, usually representing them with x instead. It uses a special representation for None that's guaranteed to never collide with any representation of Some x.

Sourcemodule Or_error : sig ... end

Type for tracking errors in an Error.t. This is a specialization of the Result type, where the Error constructor carries an Error.t.

Sourcemodule Ordered_collection_common : sig ... end

Functions for ordered collections.

Sourcemodule Ordering : sig ... end

Ordering is intended to make code that matches on the result of a comparison more concise and easier to read.

Sourcemodule Poly : sig ... end

A module containing the ad-hoc polymorphic comparison functions. Useful when you want to use polymorphic compare in some small scope of a file within which polymorphic compare has been hidden

Sourcemodule Popcount : sig ... end
Sourcemodule Pretty_printer : sig ... end

A list of pretty printers for various types, for use in toplevels.

Sourcemodule Printf : sig ... end

Functions for formatted output.

Sourcemodule Linked_queue : sig ... end

This module is a Base-style wrapper around OCaml's standard Queue module.

Sourcemodule Queue : sig ... end

A queue implemented with an array.

Sourcemodule Random : sig ... end

Pseudo-random number generation.

Sourcemodule Ref : sig ... end

Module for the type ref, mutable indirection cells r containing a value of type 'a, accessed with !r and set by r := a.

Sourcemodule Result : sig ... end

Result is often used to handle error messages.

Sourcemodule Sequence : sig ... end

A sequence of elements that can be produced one at a time, on demand, normally with no sharing.

Sourcemodule Set : sig ... end

Sets based on Comparator.S.

Sourcemodule Sexpable : sig ... end

Provides functors for making modules sexpable when you want the sexp representation of one type to be the same as that for some other isomorphic type.

Sourcemodule Sign : sig ... end

A type for representing the sign of a numeric value.

Sourcemodule Sign_or_nan : sig ... end

An extension to Sign with a Nan constructor, for representing the sign of float-like numeric values.

Sourcemodule Source_code_position : sig ... end

One typically obtains a Source_code_position.t using a [%here] expression, which is implemented by the ppx_here preprocessor.

Sourcemodule Stack : sig ... end
Sourcemodule Staged : sig ... end

A type for making staging explicit in the type of a function.

Sourcemodule String : sig ... end

An extension of the standard StringLabels. If you open Base, you'll get these extensions in the String module.

Sourcemodule Stringable : sig ... end

Provides type-specific conversion functions to and from string.

Sourcemodule Sys : sig ... end

Cross-platform system configuration values.

Sourcemodule T : sig ... end

This module defines various abstract interfaces that are convenient when one needs a module that matches a bare signature with just a type. This sometimes occurs in functor arguments and in interfaces.

Sourcemodule Type_equal : sig ... end

The purpose of Type_equal is to represent type equalities that the type checker otherwise would not know, perhaps because the type equality depends on dynamic data, or perhaps because the type system isn't powerful enough.

Sourcemodule Uniform_array : sig ... end

Same semantics as 'a Array.t, except it's guaranteed that the representation array is not tagged with Double_array_tag, the tag for float arrays.

Sourcemodule Unit : sig ... end

Module for the type unit.

Sourcemodule Uchar : sig ... end

Unicode character operations.

Sourcemodule Variant : sig ... end

First-class representative of an individual variant in a variant type, used in [@@deriving variants].

Sourcemodule With_return : sig ... end

with_return f allows for something like the return statement in C within f.

Sourcemodule Word_size : sig ... end

For determining the word size that the program is using.

include module type of struct include T end
Sourcemodule type T = T.T
Sourcemodule type T1 = T.T1
Sourcemodule type T2 = T.T2
Sourcemodule type T3 = T.T3
Sourcemodule Sexp : sig ... end
Sourcemodule Export : sig ... end
include module type of struct include Export end
Sourcetype 'a array = 'a Array.t
Sourceval compare_array : 'a. ('a -> 'a -> int) -> 'a array -> 'a array -> int
Sourceval equal_array : 'a. ('a -> 'a -> bool) -> 'a array -> 'a array -> bool
Sourceval globalize_array : 'a. ('a -> 'a) -> 'a array -> 'a array
Sourceval array_of_sexp : 'a. (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a array
Sourceval sexp_of_array : 'a. ('a -> Sexplib0.Sexp.t) -> 'a array -> Sexplib0.Sexp.t
Sourceval array_sexp_grammar : 'a. 'a Sexplib0.Sexp_grammar.t -> 'a array Sexplib0.Sexp_grammar.t
Sourcetype bool = Bool.t
Sourceval compare_bool : bool -> bool -> int
Sourceval equal_bool : bool -> bool -> bool
Sourceval globalize_bool : bool -> bool
Sourceval hash_fold_bool : Hash.state -> bool -> Hash.state
Sourceval hash_bool : bool -> Hash.hash_value
Sourceval bool_of_sexp : Sexplib0.Sexp.t -> bool
Sourceval sexp_of_bool : bool -> Sexplib0.Sexp.t
Sourceval bool_sexp_grammar : bool Sexplib0.Sexp_grammar.t
Sourcetype char = Char.t
Sourceval compare_char : char -> char -> int
Sourceval equal_char : char -> char -> bool
Sourceval globalize_char : char -> char
Sourceval hash_fold_char : Hash.state -> char -> Hash.state
Sourceval hash_char : char -> Hash.hash_value
Sourceval char_of_sexp : Sexplib0.Sexp.t -> char
Sourceval sexp_of_char : char -> Sexplib0.Sexp.t
Sourceval char_sexp_grammar : char Sexplib0.Sexp_grammar.t
Sourcetype exn = Exn.t
Sourceval sexp_of_exn : exn -> Sexplib0.Sexp.t
Sourcetype float = Float.t
Sourceval compare_float : float -> float -> int
Sourceval equal_float : float -> float -> bool
Sourceval globalize_float : float -> float
Sourceval hash_fold_float : Hash.state -> float -> Hash.state
Sourceval hash_float : float -> Hash.hash_value
Sourceval float_of_sexp : Sexplib0.Sexp.t -> float
Sourceval sexp_of_float : float -> Sexplib0.Sexp.t
Sourceval float_sexp_grammar : float Sexplib0.Sexp_grammar.t
Sourcetype int = Int.t
Sourceval compare_int : int -> int -> int
Sourceval equal_int : int -> int -> bool
Sourceval globalize_int : int -> int
Sourceval hash_fold_int : Hash.state -> int -> Hash.state
Sourceval hash_int : int -> Hash.hash_value
Sourceval int_of_sexp : Sexplib0.Sexp.t -> int
Sourceval sexp_of_int : int -> Sexplib0.Sexp.t
Sourceval int_sexp_grammar : int Sexplib0.Sexp_grammar.t
Sourcetype int32 = Int32.t
Sourceval compare_int32 : int32 -> int32 -> int
Sourceval equal_int32 : int32 -> int32 -> bool
Sourceval globalize_int32 : int32 -> int32
Sourceval hash_fold_int32 : Hash.state -> int32 -> Hash.state
Sourceval hash_int32 : int32 -> Hash.hash_value
Sourceval int32_of_sexp : Sexplib0.Sexp.t -> int32
Sourceval sexp_of_int32 : int32 -> Sexplib0.Sexp.t
Sourceval int32_sexp_grammar : int32 Sexplib0.Sexp_grammar.t
Sourcetype int64 = Int64.t
Sourceval compare_int64 : int64 -> int64 -> int
Sourceval equal_int64 : int64 -> int64 -> bool
Sourceval globalize_int64 : int64 -> int64
Sourceval hash_fold_int64 : Hash.state -> int64 -> Hash.state
Sourceval hash_int64 : int64 -> Hash.hash_value
Sourceval int64_of_sexp : Sexplib0.Sexp.t -> int64
Sourceval sexp_of_int64 : int64 -> Sexplib0.Sexp.t
Sourceval int64_sexp_grammar : int64 Sexplib0.Sexp_grammar.t
Sourcetype 'a list = 'a List.t
Sourceval compare_list : 'a. ('a -> 'a -> int) -> 'a list -> 'a list -> int
Sourceval equal_list : 'a. ('a -> 'a -> bool) -> 'a list -> 'a list -> bool
Sourceval globalize_list : 'a. ('a -> 'a) -> 'a list -> 'a list
Sourceval hash_fold_list : 'a. (Hash.state -> 'a -> Hash.state) -> Hash.state -> 'a list -> Hash.state
Sourceval list_of_sexp : 'a. (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a list
Sourceval sexp_of_list : 'a. ('a -> Sexplib0.Sexp.t) -> 'a list -> Sexplib0.Sexp.t
Sourceval list_sexp_grammar : 'a. 'a Sexplib0.Sexp_grammar.t -> 'a list Sexplib0.Sexp_grammar.t
Sourcetype nativeint = Nativeint.t
Sourceval compare_nativeint : nativeint -> nativeint -> int
Sourceval equal_nativeint : nativeint -> nativeint -> bool
Sourceval globalize_nativeint : nativeint -> nativeint
Sourceval hash_fold_nativeint : Hash.state -> nativeint -> Hash.state
Sourceval hash_nativeint : nativeint -> Hash.hash_value
Sourceval nativeint_of_sexp : Sexplib0.Sexp.t -> nativeint
Sourceval sexp_of_nativeint : nativeint -> Sexplib0.Sexp.t
Sourceval nativeint_sexp_grammar : nativeint Sexplib0.Sexp_grammar.t
Sourcetype 'a option = 'a Option.t
Sourceval compare_option : 'a. ('a -> 'a -> int) -> 'a option -> 'a option -> int
Sourceval equal_option : 'a. ('a -> 'a -> bool) -> 'a option -> 'a option -> bool
Sourceval globalize_option : 'a. ('a -> 'a) -> 'a option -> 'a option
Sourceval hash_fold_option : 'a. (Hash.state -> 'a -> Hash.state) -> Hash.state -> 'a option -> Hash.state
Sourceval option_of_sexp : 'a. (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a option
Sourceval sexp_of_option : 'a. ('a -> Sexplib0.Sexp.t) -> 'a option -> Sexplib0.Sexp.t
Sourceval option_sexp_grammar : 'a. 'a Sexplib0.Sexp_grammar.t -> 'a option Sexplib0.Sexp_grammar.t
Sourcetype 'a ref = 'a Ref.t
Sourceval compare_ref : 'a. ('a -> 'a -> int) -> 'a ref -> 'a ref -> int
Sourceval equal_ref : 'a. ('a -> 'a -> bool) -> 'a ref -> 'a ref -> bool
Sourceval globalize_ref : 'a. ('a -> 'a) -> 'a ref -> 'a ref
Sourceval ref_of_sexp : 'a. (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a ref
Sourceval sexp_of_ref : 'a. ('a -> Sexplib0.Sexp.t) -> 'a ref -> Sexplib0.Sexp.t
Sourceval ref_sexp_grammar : 'a. 'a Sexplib0.Sexp_grammar.t -> 'a ref Sexplib0.Sexp_grammar.t
Sourcetype string = String.t
Sourceval compare_string : string -> string -> int
Sourceval equal_string : string -> string -> bool
Sourceval globalize_string : string -> string
Sourceval hash_fold_string : Hash.state -> string -> Hash.state
Sourceval hash_string : string -> Hash.hash_value
Sourceval string_of_sexp : Sexplib0.Sexp.t -> string
Sourceval sexp_of_string : string -> Sexplib0.Sexp.t
Sourceval string_sexp_grammar : string Sexplib0.Sexp_grammar.t
Sourcetype bytes = Bytes.t
Sourceval compare_bytes : bytes -> bytes -> int
Sourceval equal_bytes : bytes -> bytes -> bool
Sourceval globalize_bytes : bytes -> bytes
Sourceval bytes_of_sexp : Sexplib0.Sexp.t -> bytes
Sourceval sexp_of_bytes : bytes -> Sexplib0.Sexp.t
Sourceval bytes_sexp_grammar : bytes Sexplib0.Sexp_grammar.t
Sourcetype unit = Unit.t
Sourceval compare_unit : unit -> unit -> int
Sourceval equal_unit : unit -> unit -> bool
Sourceval globalize_unit : unit -> unit
Sourceval hash_fold_unit : Hash.state -> unit -> Hash.state
Sourceval hash_unit : unit -> Hash.hash_value
Sourceval unit_of_sexp : Sexplib0.Sexp.t -> unit
Sourceval sexp_of_unit : unit -> Sexplib0.Sexp.t
Sourceval unit_sexp_grammar : unit Sexplib0.Sexp_grammar.t

Format stuff

Sourcetype nonrec ('a, 'b, 'c) format = ('a, 'b, 'c) format
Sourcetype nonrec ('a, 'b, 'c, 'd) format4 = ('a, 'b, 'c, 'd) format4
Sourcetype nonrec ('a, 'b, 'c, 'd, 'e, 'f) format6 = ('a, 'b, 'c, 'd, 'e, 'f) format6

List operators

include module type of struct include List.Infix end
Sourceval (@) : 'a List.t -> 'a List.t -> 'a List.t

Int operators and comparisons

include module type of struct include Int.O end
Sourceval (+) : Int.t -> Int.t -> Int.t
Sourceval (-) : Int.t -> Int.t -> Int.t
Sourceval (*) : Int.t -> Int.t -> Int.t
Sourceval (/) : Int.t -> Int.t -> Int.t
Sourceval (~-) : Int.t -> Int.t
Sourceval (**) : Int.t -> Int.t -> Int.t
Sourceval (land) : Int.t -> Int.t -> Int.t
Sourceval (lor) : Int.t -> Int.t -> Int.t
Sourceval (lxor) : Int.t -> Int.t -> Int.t
Sourceval lnot : Int.t -> Int.t
Sourceval abs : Int.t -> Int.t
Sourceval neg : Int.t -> Int.t
Sourceval zero : Int.t
Sourceval (%) : Int.t -> Int.t -> Int.t
Sourceval (/%) : Int.t -> Int.t -> Int.t
Sourceval (//) : Int.t -> Int.t -> float
Sourceval (lsl) : Int.t -> int -> Int.t
Sourceval (asr) : Int.t -> int -> Int.t
Sourceval (lsr) : Int.t -> int -> Int.t
Sourceval (=) : int -> int -> bool
Sourceval (<>) : int -> int -> bool
Sourceval (<) : int -> int -> bool
Sourceval (>) : int -> int -> bool
Sourceval (<=) : int -> int -> bool
Sourceval (>=) : int -> int -> bool
Sourceval compare : int -> int -> int
Sourceval equal : int -> int -> bool
Sourceval ascending : int -> int -> int
Sourceval descending : int -> int -> int
Sourceval max : int -> int -> int
Sourceval min : int -> int -> int

Float operators

include module type of struct include Float.O_dot end
Sourceval (+.) : Float.t -> Float.t -> Float.t
Sourceval (-.) : Float.t -> Float.t -> Float.t
Sourceval (*.) : Float.t -> Float.t -> Float.t
Sourceval (/.) : Float.t -> Float.t -> Float.t
Sourceval (%.) : Float.t -> Float.t -> Float.t
Sourceval (**.) : Float.t -> Float.t -> Float.t
Sourceval (~-.) : Float.t -> Float.t
Sourceval (|>) : 'a -> ('a -> 'b) -> 'b

Reverse application operator. x |> g |> f is equivalent to f (g (x)).

Sourceval (@@) : ('a -> 'b) -> 'a -> 'b

Application operator. g @@ f @@ x is equivalent to g (f (x)).

Boolean operations

Sourceval (&&) : bool -> bool -> bool
Sourceval (||) : bool -> bool -> bool
Sourceval not : bool -> bool
Sourceval ignore : _ -> unit

Common string operations

Reference operations

Sourceval (!) : 'a ref -> 'a
Sourceval ref : 'a -> 'a ref
Sourceval (:=) : 'a ref -> 'a -> unit

Pair operations

Sourceval fst : ('a * 'b) -> 'a
Sourceval snd : ('a * 'b) -> 'b

Exceptions stuff

Sourceval raise : exn -> _
Sourceval failwith : string -> 'a
Sourceval invalid_arg : string -> 'a
Sourceval raise_s : Sexp.t -> 'a

Misc

Sourceval phys_equal : 'a -> 'a -> bool
Sourceval force : 'a Lazy.t -> 'a
Sourcemodule Continue_or_stop = Container.Continue_or_stop

Continue_or_stop.t is used by the f argument to fold_until in order to indicate whether folding should continue, or stop early.

Sourceexception Not_found_s of Sexplib0.Sexp.t