Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Monolith.Gen
SourceThe submodule Gen
offers facilities for generating values of many common types.
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.
guard b
fails if b
is false.
byte
generates a byte. A byte is viewed as an unsigned integer. It is therefore a value in the semi-open interval [0, 256)
.
int n
generates an integer in the semi-open interval [0, n)
. If this interval is empty, the generator fails.
semi_open_interval i j
generates an integer in the semi-open interval [i, j)
. If this interval is empty, the generator fails.
closed_interval i j
generates an integer in the closed interval [i, j]
. If this interval is empty, the generator fails.
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.
choose xs
picks an element in the list xs
. If this list is empty, the generator fails.
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.
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.