Safe Haskell | None |
---|---|
Language | Haskell2010 |
Simple GHC.Generics-based arbitrary
generators.
For more information:
- genericArbitrary :: (Generic a, GA Unsized (Rep a)) => Weights a -> Gen a
- genericArbitraryU :: (Generic a, GA Unsized (Rep a), UniformWeight_ (Rep a)) => Gen a
- genericArbitrarySingle :: (Generic a, GA Unsized (Rep a), Weights_ (Rep a) ~ L c0) => Gen a
- genericArbitrary' :: (Generic a, GA Sized (Rep a), BaseCase a) => Weights a -> Gen a
- genericArbitraryU' :: (Generic a, GA Sized (Rep a), BaseCase a, UniformWeight_ (Rep a)) => Gen a
- genericArbitraryRec :: forall a. (Generic a, GA Sized (Rep a)) => Weights a -> Gen a
- data Weights a
- data W c
- (%) :: WeightBuilder' w => W (First' w) -> Prec' w -> w
- uniform :: UniformWeight_ (Rep a) => Weights a
- withBaseCase :: Gen a -> Gen a -> Gen a
- class BaseCase a where
- weights :: (Weights_ (Rep a), Int, ()) -> Weights a
Arbitrary implementations
Pick a constructor with a given distribution, and fill its fields
with recursive calls to arbitrary
.
Example
genericArbitrary (2 % 3 % 5 % ()) :: Gen a
Picks the first constructor with probability 2/10
,
the second with probability 3/10
, the third with probability 5/10
.
genericArbitraryU :: (Generic a, GA Unsized (Rep a), UniformWeight_ (Rep a)) => Gen a Source #
Pick every constructor with equal probability.
Equivalent to
.genericArbitrary
uniform
genericArbitraryU :: Gen a
genericArbitrarySingle :: (Generic a, GA Unsized (Rep a), Weights_ (Rep a) ~ L c0) => Gen a Source #
arbitrary
for types with one constructor.
Equivalent to genericArbitraryU
, with a stricter type.
genericArbitrarySingle :: Gen a
:: (Generic a, GA Sized (Rep a), BaseCase a) | |
=> Weights a | List of weights for every constructor |
-> Gen a |
Decrease size to ensure termination for recursive types, looking for base cases once the size reaches 0.
genericArbitrary' (17 % 19 % 23 % ()) :: Gen a
genericArbitraryU' :: (Generic a, GA Sized (Rep a), BaseCase a, UniformWeight_ (Rep a)) => Gen a Source #
Equivalent to
.genericArbitrary'
uniform
genericArbitraryU :: Gen a
Decrease size at every recursive call, but don't do anything different at size 0.
genericArbitraryRec (7 % 11 % 13 % ()) :: Gen a
Specifying finite distributions
Trees of weights assigned to constructors of type a
,
rescaled to obtain a probability distribution.
Two ways of constructing them.
(x1%
x2%
...%
xn%
()) ::Weights
auniform
::Weights
a
Using (
, there must be exactly as many weights as
there are constructors.%
)
uniform
is equivalent to (1
(automatically fills out the right number of 1s).%
... %
1 %
())
WeightBuilder (Weights_ (Rep a)) => WeightBuilder' (Weights a) Source # | |
(%) :: WeightBuilder' w => W (First' w) -> Prec' w -> w Source #
A binary constructor for building up trees of weights.
Base cases for recursive types
withBaseCase :: Gen a -> Gen a -> Gen a Source #
Run the first generator if the size is positive. Run the second if the size is zero.
defaultGen `withBaseCase` baseCaseGen