package batteries

  1. Overview
  2. Docs
A community-maintained standard library extension

Install

Dune Dependency

Authors

Maintainers

Sources

v3.5.1.tar.gz
md5=d3d16ffc960e832a1c0e21b7123194e9
sha512=36c8561079aa9fefc864c2f03bd8ae20aa05987bb67e7a9beac3ab4f440dbf7d44f141c172b05fddb1a5b618fc55a27962bb45fc39bd7b3a15d56e0ed3ff3870

doc/batteries.unthreaded/BatGlobal/index.html

Module BatGlobal

Mutable global variable.

Often in OCaml you want to have a global variable, which is mutable and uninitialized when declared. You can use a 'a option ref but this is not very convenient. The Global module provides functions to easily create and manipulate such variables.

  • author Nicolas Cannasse
  • author David Teller (boilerplate code)
type 'a t

Abstract type of a global

exception Global_not_initialized of string

Raised when a global variable is accessed without first having been assigned a value. The parameter contains the name of the global.

val empty : string -> 'a t

Returns an new named empty global. The name of the global can be any string. It identifies the global and makes debugging easier. Using the same string twice will not return the same global twice, but will create two globals with the same name.

val name : 'a t -> string

Retrieve the name of a global.

val set : 'a t -> 'a -> unit

Set the global value contents.

val get_exn : 'a t -> 'a

Get the global value contents - raise Global_not_initialized if not defined.

val get : 'a t -> 'a option

Return None if the global is undefined, else Some v where v is the current global value contents.

val undef : 'a t -> unit

Reset the global value contents to undefined.

val isdef : 'a t -> bool

Return true if the global value has been set.

OCaml

Innovation. Community. Security.