Gen
Monad #
This monad is used to formulate randomized computations with a parameter to specify the desired size of the result.
Main definitions #
Gen
monad
References #
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.
Equations
- Plausible.Gen α = ReaderT (ULift Nat) Plausible.Rand α
Instances For
Equations
- x.up = do let size ← read liftM (Plausible.Rand.up (ReaderT.run x { down := size.down }))
Instances For
Equations
- x.down = do let size ← read liftM (Plausible.Rand.down (ReaderT.run x { down := size.down }))
Instances For
Lift BoundedRandom.randomR
to the Gen
monad.
Equations
- Plausible.Gen.choose α lo hi h x✝ = Plausible.Random.randBound α lo hi h
Instances For
Generate a Nat
example between lo
and hi
(exclusively).
Equations
- Plausible.Gen.chooseNatLt lo hi h = do let __discr ← Plausible.Gen.choose Nat (lo + 1) hi ⋯ match __discr with | ⟨val, h⟩ => pure ⟨val - 1, ⋯⟩
Instances For
Get access to the size parameter of the Gen
monad.
Equations
- Plausible.Gen.getSize = do let __do_lift ← read pure __do_lift.down
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
Given a list of example generators, choose one to create an example.
Equations
- Plausible.Gen.oneOf xs pos = do let __discr ← (Plausible.Gen.chooseNatLt 0 xs.size pos).up match __discr with | { down := ⟨x, ⋯⟩ } => xs[x]
Instances For
Given a list of examples, choose one to create an example.
Equations
- Plausible.Gen.elements xs pos = do let __discr ← (Plausible.Gen.chooseNatLt 0 xs.length pos).up match __discr with | { down := ⟨x, ⋯⟩ } => pure xs[x]
Instances For
Generate a random permutation of a given list.
Equations
- One or more equations did not get rendered due to their size.
- Plausible.Gen.permutationOf [] = pure ⟨[], ⋯⟩
Instances For
Given two generators produces a tuple consisting out of the result of both
Equations
Instances For
Execute a Gen
inside the IO
monad using size
as the example size
Equations
- x.run size = Plausible.runRand (liftM (ReaderT.run x { down := size }))