module Raw_quickcheck_generator:sig
..end
Quickcheck_generator
for an overview.type 'a
t
val bind : 'a t ->
('a -> 'b t) -> 'b t
bind t f
is a monadic bind that replaces each value x
that has probability p
in
t
with the probability distribution f x
weighted proportionally by p
.
singleton
, below, corresponds to monadic return.module Choice:sig
..end
with type 'a gen := 'a t
'a Choice.t
represents the choice of a value from a generator.
val bind_choice : 'a t ->
('a Choice.t -> 'b t) ->
'b t
bind_choice t f
is like bind t f
, except f
is passed an 'a Choice.t
and can
thus use subsets of t
by using Choice.gen
with the ~keep
option.
bind t f
is equal to bind_choice t (fun c -> f (Choice.value c))
, although bind
is cheaper than bind_choice
.
val failure : 'a t
val singleton : 'a -> 'a t
singleton t
is equal to return t
.val weighted_union : (float * 'a t) list -> 'a t
weighted_union alist
produces a generator that combines the distributions of each
t
in alist
with the associated weights, which must be finite positive floating
point values.val of_fun : (unit -> 'a t) -> 'a t
of_fun f
produces a generator that lazily applies f
.
f
*MUST* be deterministic or else random value generation will fail. However, it is
recommended that f
not be memoized. Instead, spread out the work of generating a
whole distribution over many of_fun
calls combined with weighted_union
. This
allows lazily generated generators to be garbage collected after each test and the
relevant portions cheaply recomputed in subsequent tests, rather than accumulating
without bound over time.
val choose : 'a t ->
random_float_between_zero_and_one:(unit -> float) ->
max_attempts:int ->
[ `Choice of 'a Choice.t
| `No_choices_remain
| `Ran_out_of_attempts ]
choose t ~random_float_between_zero_and_one
makes a choice in t
at random, using
random_float_between_zero_and_one
to produce random floats between 0. (inclusive)
and 1. (exclusive) for each weighted choice. If t
has been fully explored, it
produces `No_choices_remain
. Otherwise it produces `Choice c
for some choice c
in t
.val inspect : 'a t ->
[ `Failure
| `Singleton of 'a
| `Weighted_union of (float * 'a t) list ]
inspect t
produces a concrete representation of the outermost constructor of t
.
It is possible to explore t
further with recursive calls to inspect
; however, be
aware that t
may be infinite.