Safe Haskell | None |
---|---|
Language | Haskell2010 |
Core implementation.
Warning
This is an internal module: it is not subject to any versioning policy, breaking changes can happen at any time.
If something here seems useful, please report it or create a pull request to export it from an external module.
Synopsis
- genericArbitrary :: GArbitrary UnsizedOpts a => Weights a -> Gen a
- genericArbitraryU :: (GArbitrary UnsizedOpts a, GUniformWeight a) => Gen a
- genericArbitrarySingle :: (GArbitrary UnsizedOpts a, Weights_ (Rep a) ~ L c0) => Gen a
- genericArbitraryRec :: GArbitrary SizedOptsDef a => Weights a -> Gen a
- genericArbitraryG :: GArbitrary (SetGens genList UnsizedOpts) a => genList -> Weights a -> Gen a
- genericArbitraryUG :: (GArbitrary (SetGens genList UnsizedOpts) a, GUniformWeight a) => genList -> Gen a
- genericArbitrarySingleG :: (GArbitrary (SetGens genList UnsizedOpts) a, Weights_ (Rep a) ~ L c0) => genList -> Gen a
- genericArbitraryRecG :: GArbitrary (SetGens genList SizedOpts) a => genList -> Weights a -> Gen a
- genericArbitraryWith :: GArbitrary opts a => opts -> Weights a -> Gen a
- type family Weights_ (f :: Type -> Type) :: Type where ...
- data a :| b = N a Int b
- data L (c :: Symbol) = L
- data Weights a = Weights (Weights_ (Rep a)) Int
- newtype W (c :: Symbol) = W Int
- weights :: (Weights_ (Rep a), Int, ()) -> Weights a
- uniform :: UniformWeight_ (Rep a) => Weights a
- type family First a :: Symbol where ...
- type family First' w where ...
- type family Prec' w where ...
- class a ~ b => a ~. b
- class WeightBuilder' w where
- class WeightBuilder a where
- class UniformWeight a where
- uniformWeight :: (a, Int)
- class UniformWeight (Weights_ f) => UniformWeight_ f
- class UniformWeight_ (Rep a) => GUniformWeight a
- newtype Options (s :: Sizing) (genList :: Type) = Options {
- _generators :: genList
- unsizedOpts :: UnsizedOpts
- sizedOpts :: SizedOpts
- sizedOptsDef :: SizedOptsDef
- data Sizing
- type UnsizedOpts = Options Unsized ()
- type SizedOpts = Options Sized ()
- type SizedOptsDef = Options Sized (Gen1 [] :+ ())
- type family SizingOf opts :: Sizing
- setSized :: Options s g -> Options Sized g
- setUnsized :: Options s g -> Options Unsized g
- data a :+ b = a :+ b
- type family GeneratorsOf opts :: Type
- class HasGenerators opts where
- generators :: opts -> GeneratorsOf opts
- setGenerators :: genList -> Options s g0 -> Options s genList
- type family SetGens (g :: Type) opts
- newtype FieldGen (s :: Symbol) a = FieldGen {
- unFieldGen :: Gen a
- fieldGen :: proxy s -> Gen a -> FieldGen s a
- newtype ConstrGen (c :: Symbol) (i :: Nat) a = ConstrGen {
- unConstrGen :: Gen a
- constrGen :: proxy '(c, i) -> Gen a -> ConstrGen c i a
- newtype Gen1 f = Gen1 {}
- newtype Gen1_ f = Gen1_ {}
- vectorOf' :: Int -> Gen a -> Gen [a]
- listOf' :: Gen a -> Gen [a]
- listOf1' :: Gen a -> Gen [a]
- geom :: Int -> Gen Int
- class GA opts f where
- class (Generic a, GA opts (Rep a)) => GArbitrary opts a
- gaSum' :: GASum opts f => opts -> Weights_ f -> Int -> Gen (f p)
- class GASum opts f where
- class GAProduct (s :: Sizing) (c :: Maybe Symbol) opts f where
- class GAProduct' (c :: Maybe Symbol) (i :: Nat) opts f where
- gaProduct' :: proxy '(c, i) -> opts -> Gen (f p)
- type family Arity f :: Nat where ...
- class ArbitraryOr (fullGenList :: Type) (g :: Type) (gs :: Type) (sel :: (Maybe Symbol, Nat, Maybe Symbol)) a where
- arbitraryOr :: proxy sel -> fullGenList -> g -> gs -> Gen a
- type family Name (d :: Meta) :: Maybe Symbol
- newtype Weighted a = Weighted (Maybe (Int -> Gen a, Int))
- liftGen :: Gen a -> Weighted a
Random generators
:: GArbitrary UnsizedOpts a | |
=> Weights a | List of weights for every constructor |
-> Gen a |
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 :: (GArbitrary UnsizedOpts a, GUniformWeight a) => Gen a Source #
Pick every constructor with equal probability.
Equivalent to
.genericArbitrary
uniform
genericArbitraryU :: Gen a
genericArbitrarySingle :: (GArbitrary UnsizedOpts 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
:: GArbitrary SizedOptsDef a | |
=> Weights a | List of weights for every constructor |
-> Gen a |
genericArbitraryG :: GArbitrary (SetGens genList UnsizedOpts) a => genList -> Weights a -> Gen a Source #
genericArbitrary
with explicit generators.
Example
genericArbitraryG customGens (17 % 19 % ())
where, for example to override generators for String
and Int
fields,
customGens :: Gen String:+
Gen Int customGens = (filter (/= '\NUL')<$>
arbitrary):+
(getNonNegative<$>
arbitrary)
Note on multiple matches
If the list contains multiple matching types for a field x
of type a
(i.e., either Gen a
or
), the generator for the first
match will be picked.FieldGen
"x" a
genericArbitraryUG :: (GArbitrary (SetGens genList UnsizedOpts) a, GUniformWeight a) => genList -> Gen a Source #
genericArbitraryU
with explicit generators.
See also genericArbitraryG
.
genericArbitrarySingleG :: (GArbitrary (SetGens genList UnsizedOpts) a, Weights_ (Rep a) ~ L c0) => genList -> Gen a Source #
genericArbitrarySingle
with explicit generators.
See also genericArbitraryG
.
:: GArbitrary (SetGens genList SizedOpts) a | |
=> genList | |
-> Weights a | List of weights for every constructor |
-> Gen a |
genericArbitraryRec
with explicit generators.
See also genericArbitraryG
.
genericArbitraryWith :: GArbitrary opts a => opts -> Weights a -> Gen a Source #
General generic generator with custom options.
Internal
Instances
(UniformWeight a, UniformWeight b) => UniformWeight (a :| b) Source # | |
Defined in Generic.Random.Internal.Generic uniformWeight :: (a :| b, Int) Source # | |
WeightBuilder a => WeightBuilder (a :| b) Source # | |
type Prec (a :| b) r Source # | |
Defined in Generic.Random.Internal.Generic |
Instances
UniformWeight (L c) Source # | |
Defined in Generic.Random.Internal.Generic uniformWeight :: (L c, Int) Source # | |
WeightBuilder (L c) Source # | |
type Prec (L c) r Source # | |
Defined in Generic.Random.Internal.Generic |
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 %
())
weights :: (Weights_ (Rep a), Int, ()) -> Weights a Source #
A smart constructor to specify a custom distribution.
It can be omitted for the %
operator is overloaded to
insert it.
class a ~ b => a ~. b Source #
A synonym for (~)
, except on GHC 7.10 and older, where it's the trivial
constraint. See note on W
.
Instances
a ~ b => (a :: k) ~. (b :: k) Source # | |
Defined in Generic.Random.Internal.Generic |
class WeightBuilder' w where Source #
(%) :: c ~. First' w => W c -> Prec' w -> w infixr 1 Source #
A binary constructor for building up trees of weights.
Instances
WeightBuilder (Weights_ (Rep a)) => WeightBuilder' (Weights a) Source # | |
WeightBuilder a => WeightBuilder' (a, Int, r) Source # | |
class WeightBuilder a where Source #
Instances
WeightBuilder () Source # | |
WeightBuilder (L c) Source # | |
WeightBuilder a => WeightBuilder (a :| b) Source # | |
class UniformWeight a where Source #
uniformWeight :: (a, Int) Source #
Instances
UniformWeight () Source # | |
Defined in Generic.Random.Internal.Generic uniformWeight :: ((), Int) Source # | |
UniformWeight (L c) Source # | |
Defined in Generic.Random.Internal.Generic uniformWeight :: (L c, Int) Source # | |
(UniformWeight a, UniformWeight b) => UniformWeight (a :| b) Source # | |
Defined in Generic.Random.Internal.Generic uniformWeight :: (a :| b, Int) Source # |
class UniformWeight (Weights_ f) => UniformWeight_ f Source #
Instances
UniformWeight (Weights_ f) => UniformWeight_ f Source # | |
Defined in Generic.Random.Internal.Generic |
class UniformWeight_ (Rep a) => GUniformWeight a Source #
Derived uniform distribution of constructors for a
.
Instances
UniformWeight_ (Rep a) => GUniformWeight a Source # | |
Defined in Generic.Random.Internal.Generic |
newtype Options (s :: Sizing) (genList :: Type) Source #
Type-level options for GArbitrary
.
Options | |
|
Instances
HasGenerators (Options s g) Source # | |
Defined in Generic.Random.Internal.Generic generators :: Options s g -> GeneratorsOf (Options s g) Source # | |
type SetGens g (Options s _g) Source # | |
Defined in Generic.Random.Internal.Generic | |
type GeneratorsOf (Options _s g) Source # | |
Defined in Generic.Random.Internal.Generic | |
type SizingOf (Options s _g) Source # | |
Defined in Generic.Random.Internal.Generic |
unsizedOpts :: UnsizedOpts Source #
Default options for unsized generators.
sizedOptsDef :: SizedOptsDef Source #
Default options overriding the list generator using listOf'
.
type UnsizedOpts = Options Unsized () Source #
Heterogeneous list of generators.
a :+ b infixr 1 |
Instances
ArbitraryOr fg b g sel a => ArbitraryOr fg () (b :+ g) sel a Source # | Examine the next candidate |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> () -> (b :+ g) -> Gen a Source # | |
ArbitraryOr fg g (h :+ gs) sel a => ArbitraryOr fg (g :+ h) gs sel a Source # | This can happen if the generators form a tree rather than a list, for whatever reason. |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> (g :+ h) -> gs -> Gen a Source # |
type family GeneratorsOf opts :: Type Source #
Instances
type GeneratorsOf (Options _s g) Source # | |
Defined in Generic.Random.Internal.Generic |
class HasGenerators opts where Source #
generators :: opts -> GeneratorsOf opts Source #
Instances
HasGenerators (Options s g) Source # | |
Defined in Generic.Random.Internal.Generic generators :: Options s g -> GeneratorsOf (Options s g) Source # |
setGenerators :: genList -> Options s g0 -> Options s genList Source #
newtype FieldGen (s :: Symbol) a Source #
Custom generator for record fields named s
.
Available only for base >= 4.9
(GHC >= 8.0.1
).
FieldGen | |
|
Instances
a ~ a' => ArbitraryOr fg (FieldGen s a) g ((,,) con i (Just s)) a' Source # | Matching custom generator for field |
Defined in Generic.Random.Internal.Generic |
fieldGen :: proxy s -> Gen a -> FieldGen s a Source #
FieldGen
constructor with the field name given via a proxy.
newtype ConstrGen (c :: Symbol) (i :: Nat) a Source #
Custom generator for the i
-th field of the constructor named c
.
Available only for base >= 4.9
(GHC >= 8.0.1
).
ConstrGen | |
|
Instances
a ~ a' => ArbitraryOr fg (ConstrGen c i a) g ((,,) (Just c) i s) a' Source # | Matching custom generator for |
Defined in Generic.Random.Internal.Generic |
constrGen :: proxy '(c, i) -> Gen a -> ConstrGen c i a Source #
ConstrGen
constructor with the constructor name given via a proxy.
Custom generators for "containers" of kind Type -> Type
, parameterized
by the generator for "contained elements".
A custom generator
will be used for any field whose type has the
form Gen1
ff x
, requiring a generator of x
.
Instances
ArbitraryOr fg () fg ((,,) (Nothing :: Maybe Symbol) 0 (Nothing :: Maybe Symbol)) a => ArbitraryOr fg (Gen1 f) g sel (f a) Source # | Matching custom generator for container |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> Gen1 f -> g -> Gen (f a) Source # |
Custom generators for unary type constructors that are not "containers",
i.e., which don't require a generator of a
to generate an f a
.
A custom generator
will be used for any field whose type has the
form Gen1_
ff x
.
Instances
ArbitraryOr fg (Gen1_ f) g sel (f a) Source # | Matching custom generator for non-container |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> Gen1_ f -> g -> Gen (f a) Source # |
vectorOf' :: Int -> Gen a -> Gen [a] Source #
An alternative to vectorOf
that divides the size parameter by the
length of the list.
listOf' :: Gen a -> Gen [a] Source #
An alternative to listOf
that divides the size parameter
by the length of the list.
The length follows a geometric distribution of parameter
1/(sqrt size + 1)
.
listOf1' :: Gen a -> Gen [a] Source #
An alternative to listOf1
(nonempty lists) that divides
the size parameter by the length of the list.
The length (minus one) follows a geometric distribution of parameter
1/(sqrt size + 1)
.
class GA opts f where Source #
Generic Arbitrary
class (Generic a, GA opts (Rep a)) => GArbitrary opts a Source #
Generic Arbitrary
Instances
(Generic a, GA opts (Rep a)) => GArbitrary opts a Source # | |
Defined in Generic.Random.Internal.Generic |
class GAProduct (s :: Sizing) (c :: Maybe Symbol) opts f where Source #
Instances
GAProduct' c 0 opts f => GAProduct Unsized c opts (f :: k -> Type) Source # | |
(GAProduct' c 0 opts f, KnownNat (Arity f)) => GAProduct Sized c opts (f :: k -> Type) Source # | |
GAProduct Sized c opts (U1 :: k -> Type) Source # | |
GAProduct' c 0 opts (S1 d f) => GAProduct Sized c opts (S1 d f :: k -> Type) Source # | |
class GAProduct' (c :: Maybe Symbol) (i :: Nat) opts f where Source #
gaProduct' :: proxy '(c, i) -> opts -> Gen (f p) Source #
Instances
GAProduct' c i opts (U1 :: k -> Type) Source # | |
Defined in Generic.Random.Internal.Generic gaProduct' :: proxy (c, i) -> opts -> Gen (U1 p) Source # | |
(GAProduct' c i opts f, GAProduct' c (i + Arity f) opts g) => GAProduct' c i opts (f :*: g :: k -> Type) Source # | |
Defined in Generic.Random.Internal.Generic gaProduct' :: proxy (c, i) -> opts -> Gen ((f :*: g) p) Source # | |
(HasGenerators opts, ArbitraryOr gs () gs ((,,) c i (Name d)) a, gs ~ GeneratorsOf opts) => GAProduct' c i opts (S1 d (K1 _k a :: k -> Type) :: k -> Type) Source # | |
Defined in Generic.Random.Internal.Generic |
class ArbitraryOr (fullGenList :: Type) (g :: Type) (gs :: Type) (sel :: (Maybe Symbol, Nat, Maybe Symbol)) a where Source #
Given a list of custom generators gs
, find one that applies, or use
Arbitrary a
by default.
g
and gs
follow this little state machine:
g, gs | result ---------------------+----------------------------- (), () | END (), g :+ gs | g, gs (), g | g, () when g is not (_ :+ _) g :+ h, gs | g, h :+ gs Gen a, gs | END if matching, else (), gs FieldGen a, gs | idem ConstrGen a, gs | idem Gen1 a, gs | idem Gen1_ a, gs | idem
arbitraryOr :: proxy sel -> fullGenList -> g -> gs -> Gen a Source #
Instances
ArbitraryOr fg () gs sel a => ArbitraryOr fg g gs sel a Source # | None of the INCOHERENT instances match, discard the candidate |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> g -> gs -> Gen a Source # | |
ArbitraryOr fg g () sel a => ArbitraryOr fg () g sel a Source # | Examine the last candidate ( |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> () -> g -> Gen a Source # | |
Arbitrary a => ArbitraryOr fg () () sel a Source # | All candidates have been exhausted |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> () -> () -> Gen a Source # | |
ArbitraryOr fg b g sel a => ArbitraryOr fg () (b :+ g) sel a Source # | Examine the next candidate |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> () -> (b :+ g) -> Gen a Source # | |
ArbitraryOr fg (Gen a) g sel a Source # | Matching custom generator for |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> Gen a -> g -> Gen a Source # | |
ArbitraryOr fg () fg ((,,) (Nothing :: Maybe Symbol) 0 (Nothing :: Maybe Symbol)) a => ArbitraryOr fg (Gen1 f) g sel (f a) Source # | Matching custom generator for container |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> Gen1 f -> g -> Gen (f a) Source # | |
ArbitraryOr fg g (h :+ gs) sel a => ArbitraryOr fg (g :+ h) gs sel a Source # | This can happen if the generators form a tree rather than a list, for whatever reason. |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> (g :+ h) -> gs -> Gen a Source # | |
ArbitraryOr fg (Gen1_ f) g sel (f a) Source # | Matching custom generator for non-container |
Defined in Generic.Random.Internal.Generic arbitraryOr :: proxy sel -> fg -> Gen1_ f -> g -> Gen (f a) Source # | |
a ~ a' => ArbitraryOr fg (FieldGen s a) g ((,,) con i (Just s)) a' Source # | Matching custom generator for field |
Defined in Generic.Random.Internal.Generic | |
a ~ a' => ArbitraryOr fg (ConstrGen c i a) g ((,,) (Just c) i s) a' Source # | Matching custom generator for |
Defined in Generic.Random.Internal.Generic |