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:

The recommended way to use Base is to build with -open Base. Files compiled this way will have the environment described in this file as their initial environment.

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

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

A type-indexed value that allows one to compare (and for generating error messages, serialize) values of the type in question.

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

A signature combining functionality that is commonly used for types that are intended to act as names or identifiers.

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

Option type.

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 Polymorphic_compare = Poly
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

This module defines the Set module for Base. Functions that construct a set take as an argument the comparator for the element type.

Sourcemodule Sexpable : sig ... end

Provides functors for making modules sexpable. New code should use the [@@deriving sexp] syntax directly. These module types (S, S1, S2, and S3) are exported for backwards compatibility only.

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 Validate : sig ... end

A module for organizing validations of data structures.

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
include module type of struct include Sexplib0.Sexp.Private.Raw_grammar.Builtin 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 array_of_sexp : 'a. (Sexp.t -> 'a) -> Sexp.t -> 'a array
Sourceval sexp_of_array : 'a. ('a -> Sexp.t) -> 'a array -> Sexp.t
Sourcetype bool = Bool.t
Sourceval compare_bool : bool -> bool -> int
Sourceval equal_bool : bool -> bool -> bool
Sourceval hash_fold_bool : Hash.state -> bool -> Hash.state
Sourceval hash_bool : bool -> Hash.hash_value
Sourceval bool_of_sexp : Sexp.t -> bool
Sourceval sexp_of_bool : bool -> Sexp.t
Sourcetype char = Char.t
Sourceval compare_char : char -> char -> int
Sourceval equal_char : char -> char -> bool
Sourceval hash_fold_char : Hash.state -> char -> Hash.state
Sourceval hash_char : char -> Hash.hash_value
Sourceval char_of_sexp : Sexp.t -> char
Sourceval sexp_of_char : char -> Sexp.t
Sourcetype exn = Exn.t
Sourceval sexp_of_exn : exn -> Sexp.t
Sourcetype float = Float.t
Sourceval compare_float : float -> float -> int
Sourceval equal_float : float -> float -> bool
Sourceval hash_fold_float : Hash.state -> float -> Hash.state
Sourceval hash_float : float -> Hash.hash_value
Sourceval float_of_sexp : Sexp.t -> float
Sourceval sexp_of_float : float -> Sexp.t
Sourcetype int = Int.t
Sourceval compare_int : int -> int -> int
Sourceval equal_int : int -> int -> bool
Sourceval hash_fold_int : Hash.state -> int -> Hash.state
Sourceval hash_int : int -> Hash.hash_value
Sourceval int_of_sexp : Sexp.t -> int
Sourceval sexp_of_int : int -> Sexp.t
Sourcetype int32 = Int32.t
Sourceval compare_int32 : int32 -> int32 -> int
Sourceval equal_int32 : int32 -> int32 -> bool
Sourceval hash_fold_int32 : Hash.state -> int32 -> Hash.state
Sourceval hash_int32 : int32 -> Hash.hash_value
Sourceval int32_of_sexp : Sexp.t -> int32
Sourceval sexp_of_int32 : int32 -> Sexp.t
Sourcetype int64 = Int64.t
Sourceval compare_int64 : int64 -> int64 -> int
Sourceval equal_int64 : int64 -> int64 -> bool
Sourceval hash_fold_int64 : Hash.state -> int64 -> Hash.state
Sourceval hash_int64 : int64 -> Hash.hash_value
Sourceval int64_of_sexp : Sexp.t -> int64
Sourceval sexp_of_int64 : int64 -> Sexp.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 hash_fold_list : 'a. (Hash.state -> 'a -> Hash.state) -> Hash.state -> 'a list -> Hash.state
Sourceval list_of_sexp : 'a. (Sexp.t -> 'a) -> Sexp.t -> 'a list
Sourceval sexp_of_list : 'a. ('a -> Sexp.t) -> 'a list -> Sexp.t
Sourcetype nativeint = Nativeint.t
Sourceval compare_nativeint : nativeint -> nativeint -> int
Sourceval equal_nativeint : nativeint -> nativeint -> bool
Sourceval hash_fold_nativeint : Hash.state -> nativeint -> Hash.state
Sourceval hash_nativeint : nativeint -> Hash.hash_value
Sourceval nativeint_of_sexp : Sexp.t -> nativeint
Sourceval sexp_of_nativeint : nativeint -> Sexp.t
Sourceval nativeint_sexp_grammar : Sexplib0.Sexp.Private.Raw_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 hash_fold_option : 'a. (Hash.state -> 'a -> Hash.state) -> Hash.state -> 'a option -> Hash.state
Sourceval option_of_sexp : 'a. (Sexp.t -> 'a) -> Sexp.t -> 'a option
Sourceval sexp_of_option : 'a. ('a -> Sexp.t) -> 'a option -> Sexp.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 ref_of_sexp : 'a. (Sexp.t -> 'a) -> Sexp.t -> 'a ref
Sourceval sexp_of_ref : 'a. ('a -> Sexp.t) -> 'a ref -> Sexp.t
Sourcetype string = String.t
Sourceval compare_string : string -> string -> int
Sourceval equal_string : string -> string -> bool
Sourceval hash_fold_string : Hash.state -> string -> Hash.state
Sourceval hash_string : string -> Hash.hash_value
Sourceval string_of_sexp : Sexp.t -> string
Sourceval sexp_of_string : string -> Sexp.t
Sourcetype bytes = Bytes.t
Sourceval compare_bytes : bytes -> bytes -> int
Sourceval equal_bytes : bytes -> bytes -> bool
Sourceval bytes_of_sexp : Sexp.t -> bytes
Sourceval sexp_of_bytes : bytes -> Sexp.t
Sourcetype unit = Unit.t
Sourceval compare_unit : unit -> unit -> int
Sourceval equal_unit : unit -> unit -> bool
Sourceval hash_fold_unit : Hash.state -> unit -> Hash.state
Sourceval hash_unit : unit -> Hash.hash_value
Sourceval unit_of_sexp : Sexp.t -> unit
Sourceval sexp_of_unit : unit -> Sexp.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

Sexp

Exporting the ad-hoc types that are recognized by ppx_sexp_* converters. sexp_array, sexp_list, and sexp_option allow a record field to be absent when converting from a sexp, and if absent, the field will take a default value of the appropriate type:

  sexp_array   [||]
  sexp_bool    false
  sexp_list    []
  sexp_option  None

sexp_opaque causes the conversion to sexp to produce the atom <opaque>.

For more documentation, see sexplib/README.md.

Sourcetype 'a sexp_array = 'a array
  • deprecated [since 2019-03] use [@sexp.array] instead
Sourcetype 'a sexp_list = 'a list
  • deprecated [since 2019-03] use [@sexp.list] instead
Sourcetype 'a sexp_opaque = 'a
  • deprecated [since 2019-03] use [@sexp.opaque] instead
Sourcetype 'a sexp_option = 'a option
  • deprecated [since 2019-03] use [@sexp.option] instead

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
include Comparisons.Infix with type 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 (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 (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 ascending : int -> int -> int
Sourceval descending : int -> int -> int
Sourceval equal : int -> int -> bool
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
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 : sig ... end

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