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
orguard
. 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 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 withint j
and withsemi_open_interval 0 j
.
val le : int -> int gen
le j
is synonymous withclosed_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 listxs
. If this list is empty, the generator fails.
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 ifelement
is an element generator thenlist n element
is a list generator.