Base
SourceThis 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:
Comparable
, Comparator
, and Comparisons
in lieu of polymorphic compare.Container
, which provides a consistent interface across container-like data structures (arrays, lists, strings).Result
, Error
, and Or_error
, supporting the or-error pattern.Fixed-length, mutable vector of elements with O(1) get
and set
operations.
Functions for performing binary searches over ordered sequences given length
and get
functions.
Boolean type extended to be enumerable, hashable, sexpable, comparable, and stringable.
OCaml's byte sequence type, semantically similar to a char array
, but taking less space in memory.
Defines functors for making modules comparable.
Comparison and serialization for a type, using a witness type to distinguish between comparison functions with different behavior.
Interfaces for infix comparison operators and comparison functions.
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:
A lazy string, implemented with Info
, but intended specifically for error messages.
The Format.formatter
type from OCaml's standard library, exported here for convenience and compatibility with other libraries.
Signatures required of types which can be used in [@@deriving hash]
.
A hash table is a mutable data structure implementing a map between keys and values. It supports constant-time lookup and in-place modification.
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.
Conversions between various integer types
This module implements derived integer operations (e.g., modulo, rounding to multiples) based on other basic operations.
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:
A value of type 'a Lazy.t
is a deferred computation, called a suspension, that has a result of type 'a
.
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.
Map
is a functional data structure (balanced binary tree) implementing finite maps over a totally-ordered domain, called a "key".
Used for specifying a bound (either upper or lower) as inclusive, exclusive, or unbounded.
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
.
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.
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.
'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
.
Type for tracking errors in an Error.t
. This is a specialization of the Result
type, where the Error
constructor carries an Error.t
.
Functions for ordered collections.
Ordering
is intended to make code that matches on the result of a comparison more concise and easier to read.
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
A list of pretty printers for various types, for use in toplevels.
This module is a Base-style wrapper around OCaml's standard Queue
module.
Module for the type ref
, mutable indirection cells r
containing a value of type 'a
, accessed with !r
and set by r := a
.
A sequence of elements that can be produced one at a time, on demand, normally with no sharing.
Sets based on Comparator.S
.
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.
An extension to Sign
with a Nan
constructor, for representing the sign of float-like numeric values.
One typically obtains a Source_code_position.t
using a [%here]
expression, which is implemented by the ppx_here
preprocessor.
An extension of the standard StringLabels
. If you open Base
, you'll get these extensions in the String
module.
Provides type-specific conversion functions to and from string
.
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.
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.
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.
First-class representative of an individual variant in a variant type, used in [@@deriving variants]
.
with_return f
allows for something like the return statement in C within f
.
include module type of struct include Export end
val hash_fold_list :
'a. (Hash.state -> 'a -> Hash.state) ->
Hash.state ->
'a list ->
Hash.state
val hash_fold_option :
'a. (Hash.state -> 'a -> Hash.state) ->
Hash.state ->
'a option ->
Hash.state
Format stuff
List operators
include module type of struct include List.Infix end
Int operators and comparisons
include module type of struct include Int.O end
Float operators
include module type of struct include Float.O_dot end
Reverse application operator. x |> g |> f
is equivalent to f (g (x))
.
Application operator. g @@ f @@ x
is equivalent to g (f (x))
.
Boolean operations
Reference operations
Pair operations
Exceptions stuff
Misc
Continue_or_stop.t
is used by the f
argument to fold_until
in order to indicate whether folding should continue, or stop early.