Gen Monad #
This monad is used to formulate randomized computations with a parameter to specify the desired size of the result.
Main definitions #
Genmonad
References #
Error thrown on generation failure, e.g. because you've run out of resources.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Plausible.instReprGenError = { reprPrec := Plausible.instReprGenError.repr }
Equations
Equations
Instances For
Equations
- Plausible.Gen.genericFailure = Plausible.GenError.genError "Generation failure."
Instances For
Monad to generate random examples to test properties with.
It has a Nat parameter so that the caller can decide on the
size of the examples. It allows failure to generate via the Except monad
Equations
- Plausible.Gen α = Plausible.RandT (ReaderT (ULift Nat) (Except Plausible.GenError)) α
Instances For
Equations
- Plausible.instMonadLiftGen = { monadLift := fun {α : Type ?u.20} (m_1 : Plausible.RandGT StdGen m α) => liftM ∘ StateT.run m_1 }
Equations
Equations
- Plausible.Gen.genFailure (Plausible.GenError.genError a) = IO.userError (toString "generation failure: " ++ toString a)
Instances For
Lift BoundedRandom.randomR to the Gen monad.
Equations
- Plausible.Gen.choose α lo hi h = liftM (Plausible.Random.randBound α lo hi h)
Instances For
Apply a function to the size parameter.
Equations
- Plausible.Gen.resize f x = withReader (ULift.up ∘ f ∘ ULift.down) x
Instances For
Choose a Nat between 0 and getSize.
Equations
- Plausible.Gen.chooseNat = do let __do_lift ← Plausible.Gen.getSize let a ← Plausible.Gen.choose Nat 0 __do_lift ⋯ pure a.val
Instances For
The following section defines various combinators for generators, which are used
in the body of derived generators (for derived Arbitrary instances).
The code for these combinators closely mirrors those used in Rocq/Coq QuickChick (see link in the References section below).
References #
Picks one of the generators in gs at random, returning the default generator
if gs is empty.
(This is a more ergonomic version of Plausible's Gen.oneOf which doesn't
require the caller to supply a proof that the list index is in bounds.)
Equations
- default.oneOfWithDefault [] = default
- default.oneOfWithDefault gs = do let idx ← Plausible.Gen.choose Nat 0 (gs.length - 1) ⋯ gs.getD idx.val default
Instances For
Given a list of example generators, choose one to create an example.
Equations
Instances For
Given a list of examples, choose one to create an example.
Equations
Instances For
Given two generators produces a tuple consisting out of the result of both
Equations
Instances For
Execute a Gen until it actually produces an output. May diverge for bad generators!
Equations
- Plausible.Gen.runUntil attempts x size = (Plausible.Gen.runUntil.repeatGen attempts x).run size