Module Monolith.Gen

The submodule Gen offers facilities for generating values of many common types.

type 'a gen = unit -> 'a

A value of type 'a gen is a generator of values of type 'a.

A generator is a function of type unit -> 'a.

A generator has the ability to draw random data from a source that is specified (on the command line) when the Monolith engine is started. An end user who wishes to implement generator does not have direct access to this source of random data, but can access it indirectly by calling other generators such as bool, byte, bits, and so on.

A generator can fail if (somehow) it detects that it has made incorrect choices and entered a dead end. It does so by invoking the functions reject or guard. This not a fatal failure. This is a silent failure that causes the engine to backtrack (to an unspecified point) and retry.

Invoking a generator is permitted only while the engine is running, that is, while a call to main is ongoing.

val reject : 'a gen

reject generates nothing. It always fails.

val guard : bool -> unit

guard b fails if b is false.

val byte : int gen

byte generates a byte. A byte is viewed as an unsigned integer. It is therefore a value in the semi-open interval [0, 256).

val bits : int gen

bits generates a signed integer.

val bool : bool gen

bool generates a Boolean value.

val char : char gen

char generates a character.

val int : int -> int gen

int n generates an integer in the semi-open interval [0, n). If this interval is empty, the generator fails.

val semi_open_interval : int -> int -> int gen

semi_open_interval i j generates an integer in the semi-open interval [i, j). If this interval is empty, the generator fails.

val closed_interval : int -> int -> int gen

closed_interval i j generates an integer in the closed interval [i, j]. If this interval is empty, the generator fails.

val lt : int -> int gen

lt j is synonymous with int j and with semi_open_interval 0 j.

val le : int -> int gen

le j is synonymous with closed_interval 0 j.

val sequential : unit -> int gen

sequential() produces a fresh stateful sequential generator of integers. This generator is deterministic. Every time this generator is invoked, it produces a new integer, counting from 0 and up.

val choose : 'a list -> 'a gen

choose xs picks an element in the list xs. If this list is empty, the generator fails.

val option : 'a gen -> 'a option gen

An option generator.

val result : 'a gen -> 'b gen -> ('a'b) Stdlib.result gen

A result generator.

val list : int gen -> 'a gen -> 'a list gen

A list generator. If n is a length generator (where a length is a nonnegative integer) and if element is an element generator then list n element is a list generator.

val array : int gen -> 'a gen -> 'a array gen

An array generator. If n is a length generator (where a length is a nonnegative integer) and if element is an element generator then array n element is a array generator.

val string : int gen -> char gen -> string gen

A string generator. If n is a length generator (where a length is a nonnegative integer) and if char is a character generator then string n char is a string generator.