package batteries

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

Install

dune-project
 Dependency

Authors

Maintainers

Sources

batteries-3.10.0.tar.gz
md5=b7f3b99f12f21b1da6b6aa13d993206d
sha512=8b7f2479eb0271bcfd9168887c1e4a9a815c512eab3ee61b150fc4dfa9ec803e4f73115155f20b3017e4a822148d0e6d1c1e8e5f96790fd691b419dd39a908a2

doc/batteries.unthreaded/BatGlobal/index.html

Module BatGlobalSource

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)
Sourcetype 'a t

Abstract type of a global

Sourceexception 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.

Sourceval 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.

Sourceval name : 'a t -> string

Retrieve the name of a global.

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

Set the global value contents.

Sourceval get_exn : 'a t -> 'a

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

Sourceval get : 'a t -> 'a option

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

Sourceval undef : 'a t -> unit

Reset the global value contents to undefined.

Sourceval isdef : 'a t -> bool

Return true if the global value has been set.