Up

Module Choice

'a Choice.t represents the choice of a value from a generator. It also encapsulates the history of which random decisions were made to reach that value, including all choices along the way that failed to produce a value.

Signature

type 'a gen = 'a t
type 'a t
val original_gen : 'a t -> 'a gen

original_gen t produces the original generator from which t was constructed, unmodified.

val updated_gen : 'a t -> keep:[
| `All_choices
| `All_choices_except_this_choice
| `Choices_to_the_left_of_this_choice_only
| `Choices_to_the_right_of_this_choice_only
| `This_choice_and_all_choices_to_the_left
| `This_choice_and_all_choices_to_the_right
] -> 'a gen

updated_gen t ~keep produces a generator representing a subset of the probability distribution from which t was constructed.

The subset determined by keep refers to notions of "left" and "right" with respect to choices in a gen. For this purpose, a generator can be thought of as a potentially infinite sequence of weighted choices, and operations on generators preserve the order of this sequence. The keep argument determines where to "cut" this sequence relative to the current choice. This property can be used to construct generators that do not repeat choices, or do not repeat the same set of choices in a different order, which is useful, e.g., for constructing lists of unique values or unique sets of values.

In all variants of keep, any failed choices that were made in constructing t are discarded.

Do not assume that a generator has any particular order: for example, do not count on an int generator being in strictly ascending order.

val value : 'a t -> 'a

value t produces the value chosen from original_gen t.

val attempts_used : 'a t -> int

attempts_used t reports the number of attempts made to choose a value. It is always at least 1, since there must have been one successful attempt; it may be higher to indicate failed attempts.