| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Generic.Random.Internal.Generic
Contents
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 :: * -> *) :: * 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 WeightBuilder' w where
- class WeightBuilder a where
- type Prec a r
- class UniformWeight a where
- 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
- proxySizing :: opts -> Proxy (SizingOf opts)
- 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
- 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 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) opts f where
- class GAProduct' opts f where
- type family Arity f :: Nat where ...
- class ArbitraryOr (fullGenList :: Type) (genList :: Type) (sel :: Maybe Symbol) a where
- type family SelectorName (d :: Meta) :: Maybe Symbol
- newtype Weighted a = Weighted (Maybe (Int -> Gen a, Int))
- liftGen :: Gen a -> Weighted a
Random generators
Arguments
| :: 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 #
Pick every constructor with equal probability.
Equivalent to .genericArbitrary uniform
genericArbitraryU :: Gen a
genericArbitrarySingle :: (GArbitrary UnsizedOpts a, Weights_ (Rep a) ~ L c0) => Gen a #
arbitrary for types with one constructor.
Equivalent to genericArbitraryU, with a stricter type.
genericArbitrarySingle :: Gen a
Arguments
| :: GArbitrary SizedOptsDef a | |
| => Weights a | List of weights for every constructor |
| -> Gen a |
Decrease size at every recursive call, but don't do anything different at size 0.
genericArbitraryRec (7 % 11 % 13 % ()) :: Gen a
N.B.: This replaces fields of type [t] with .listOf' arbitrary
genericArbitraryG :: GArbitrary (SetGens genList UnsizedOpts) a => genList -> Weights a -> Gen a #
genericArbitrary with explicit generators.
Example
genericArbitraryG customGens (17 % 19 % ())
where, for example to override generators for String and Int fields,
customGens ::GenList'[String, Int] customGens = (filter (/= '\NUL')<$>arbitrary):@(getNonNegative<$>arbitrary):@Nil
Note on multiple matches
If the list contains multiple matching types for a field x of type a
(i.e., either a or ), the generator for the first
match will be picked.Field "x" a
genericArbitraryUG :: (GArbitrary (SetGens genList UnsizedOpts) a, GUniformWeight a) => genList -> Gen a #
genericArbitraryU with explicit generators.
See also genericArbitraryG.
genericArbitrarySingleG :: (GArbitrary (SetGens genList UnsizedOpts) a, Weights_ (Rep a) ~ L c0) => genList -> Gen a #
genericArbitrarySingle with explicit generators.
See also genericArbitraryG.
Arguments
| :: 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 #
General generic generator with custom options.
Internal
Instances
| (UniformWeight a, UniformWeight b) => UniformWeight (a :| b) # | |
Defined in Generic.Random.Internal.Generic Methods uniformWeight :: (a :| b, Int) # | |
| WeightBuilder a => WeightBuilder (a :| b) # | |
| type Prec (a :| b) r # | |
Defined in Generic.Random.Internal.Generic | |
Constructors
| L |
Instances
| UniformWeight (L c) # | |
Defined in Generic.Random.Internal.Generic Methods uniformWeight :: (L c, Int) # | |
| WeightBuilder (L c) # | |
| type Prec (L c) r # | |
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%()) ::Weightsauniform::Weightsa
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 % ())
Instances
| WeightBuilder (Weights_ (Rep a)) => WeightBuilder' (Weights a) # | |
weights :: (Weights_ (Rep a), Int, ()) -> Weights a #
A smart constructor to specify a custom distribution.
It can be omitted for the % operator is overloaded to
insert it.
uniform :: UniformWeight_ (Rep a) => Weights a #
Uniform distribution.
class WeightBuilder' w where #
Minimal complete definition
Methods
(%) :: W (First' w) -> Prec' w -> w infixr 1 #
A binary constructor for building up trees of weights.
Instances
| WeightBuilder (Weights_ (Rep a)) => WeightBuilder' (Weights a) # | |
| WeightBuilder a => WeightBuilder' (a, Int, r) # | |
class WeightBuilder a where #
Minimal complete definition
Instances
| WeightBuilder () # | |
| WeightBuilder (L c) # | |
| WeightBuilder a => WeightBuilder (a :| b) # | |
class UniformWeight a where #
Minimal complete definition
Methods
uniformWeight :: (a, Int) #
Instances
| UniformWeight () # | |
Defined in Generic.Random.Internal.Generic Methods uniformWeight :: ((), Int) # | |
| UniformWeight (L c) # | |
Defined in Generic.Random.Internal.Generic Methods uniformWeight :: (L c, Int) # | |
| (UniformWeight a, UniformWeight b) => UniformWeight (a :| b) # | |
Defined in Generic.Random.Internal.Generic Methods uniformWeight :: (a :| b, Int) # | |
class UniformWeight (Weights_ f) => UniformWeight_ f #
Instances
| UniformWeight (Weights_ f) => UniformWeight_ f # | |
Defined in Generic.Random.Internal.Generic | |
class UniformWeight_ (Rep a) => GUniformWeight a #
Derived uniform distribution of constructors for a.
Instances
| UniformWeight_ (Rep a) => GUniformWeight a # | |
Defined in Generic.Random.Internal.Generic | |
newtype Options (s :: Sizing) (genList :: Type) #
Type-level options for GArbitrary.
Constructors
| Options | |
Fields
| |
Instances
| HasGenerators (Options s g) # | |
Defined in Generic.Random.Internal.Generic Methods generators :: Options s g -> GeneratorsOf (Options s g) # | |
| type SetGens g (Options s _g) # | |
Defined in Generic.Random.Internal.Generic | |
| type GeneratorsOf (Options _s g) # | |
Defined in Generic.Random.Internal.Generic | |
| type SizingOf (Options s _g) # | |
Defined in Generic.Random.Internal.Generic | |
Default options for unsized generators.
sizedOptsDef :: SizedOptsDef #
Default options overriding the list generator using listOf'.
Whether to decrease the size parameter before generating fields.
type UnsizedOpts = Options Unsized () #
proxySizing :: opts -> Proxy (SizingOf opts) #
setUnsized :: Options s g -> Options Unsized g #
Heterogeneous list of generators.
Constructors
| a :+ b infixr 1 |
Instances
| ArbitraryOr fg g sel a => ArbitraryOr fg (b :+ g) sel a # | |
Defined in Generic.Random.Internal.Generic Methods arbitraryOr :: proxy sel -> fg -> (b :+ g) -> Gen a # | |
| ArbitraryOr fg (Gen a :+ g) sel a # | |
Defined in Generic.Random.Internal.Generic Methods arbitraryOr :: proxy sel -> fg -> (Gen a :+ g) -> Gen a # | |
| ArbitraryOr fg fg (Nothing :: Maybe Symbol) a => ArbitraryOr fg (Gen1 f :+ g) sel (f a) # | |
Defined in Generic.Random.Internal.Generic Methods arbitraryOr :: proxy sel -> fg -> (Gen1 f :+ g) -> Gen (f a) # | |
| ArbitraryOr fg (Gen1_ f :+ g) sel (f a) # | |
Defined in Generic.Random.Internal.Generic Methods arbitraryOr :: proxy sel -> fg -> (Gen1_ f :+ g) -> Gen (f a) # | |
| ArbitraryOr fg (FieldGen n a :+ g) (Just n) a # | |
Defined in Generic.Random.Internal.Generic | |
type family GeneratorsOf opts :: Type #
Instances
| type GeneratorsOf (Options _s g) # | |
Defined in Generic.Random.Internal.Generic | |
class HasGenerators opts where #
Minimal complete definition
Methods
generators :: opts -> GeneratorsOf opts #
Instances
| HasGenerators (Options s g) # | |
Defined in Generic.Random.Internal.Generic Methods generators :: Options s g -> GeneratorsOf (Options s g) # | |
setGenerators :: genList -> Options s g0 -> Options s genList #
newtype FieldGen (s :: Symbol) a #
A generator which overrides a specific field named s.
Available only for base >= 4.9.
Constructors
| FieldGen | |
Fields
| |
Instances
| ArbitraryOr fg (FieldGen n a :+ g) (Just n) a # | |
Defined in Generic.Random.Internal.Generic | |
fieldGen :: proxy s -> Gen a -> FieldGen s a #
Field constructor with the field name given via a proxy.
Generators for containers of kind * -> *, parameterized by
the generator for each element.
Instances
| ArbitraryOr fg fg (Nothing :: Maybe Symbol) a => ArbitraryOr fg (Gen1 f :+ g) sel (f a) # | |
Defined in Generic.Random.Internal.Generic Methods arbitraryOr :: proxy sel -> fg -> (Gen1 f :+ g) -> Gen (f a) # | |
Generators for unary type constructors that are not containers.
Instances
| ArbitraryOr fg (Gen1_ f :+ g) sel (f a) # | |
Defined in Generic.Random.Internal.Generic Methods arbitraryOr :: proxy sel -> fg -> (Gen1_ f :+ g) -> Gen (f a) # | |
vectorOf' :: Int -> Gen a -> Gen [a] #
An alternative to vectorOf that divides the size parameter by the
length of the list.
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] #
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).
Generic Arbitrary
Minimal complete definition
class (Generic a, GA opts (Rep a)) => GArbitrary opts a #
Generic Arbitrary
Instances
| (Generic a, GA opts (Rep a)) => GArbitrary opts a # | |
Defined in Generic.Random.Internal.Generic | |
Minimal complete definition
class GAProduct (s :: Sizing) opts f where #
Minimal complete definition
Instances
| GAProduct' opts f => GAProduct Unsized opts (f :: k -> *) # | |
Defined in Generic.Random.Internal.Generic | |
| (GAProduct' opts f, KnownNat (Arity f)) => GAProduct Sized opts (f :: k -> *) # | |
Defined in Generic.Random.Internal.Generic | |
| GAProduct Sized opts (U1 :: k -> *) # | |
| GAProduct' opts (S1 d f) => GAProduct Sized opts (S1 d f :: k -> *) # | |
class GAProduct' opts f where #
Minimal complete definition
Methods
gaProduct' :: opts -> Gen (f p) #
Instances
| GAProduct' opts (U1 :: k -> *) # | |
Defined in Generic.Random.Internal.Generic Methods gaProduct' :: opts -> Gen (U1 p) # | |
| (GAProduct' opts f, GAProduct' opts g) => GAProduct' opts (f :*: g :: k -> *) # | |
Defined in Generic.Random.Internal.Generic Methods gaProduct' :: opts -> Gen ((f :*: g) p) # | |
| (HasGenerators opts, ArbitraryOr gs gs (SelectorName d) c, gs ~ GeneratorsOf opts) => GAProduct' opts (S1 d (K1 i c :: k -> *) :: k -> *) # | |
Defined in Generic.Random.Internal.Generic Methods gaProduct' :: opts -> Gen (S1 d (K1 i c) p) # | |
class ArbitraryOr (fullGenList :: Type) (genList :: Type) (sel :: Maybe Symbol) a where #
Minimal complete definition
Methods
arbitraryOr :: proxy sel -> fullGenList -> genList -> Gen a #
Instances
| Arbitrary a => ArbitraryOr fg () sel a # | |
Defined in Generic.Random.Internal.Generic Methods arbitraryOr :: proxy sel -> fg -> () -> Gen a # | |
| ArbitraryOr fg g sel a => ArbitraryOr fg (b :+ g) sel a # | |
Defined in Generic.Random.Internal.Generic Methods arbitraryOr :: proxy sel -> fg -> (b :+ g) -> Gen a # | |
| ArbitraryOr fg (Gen a :+ g) sel a # | |
Defined in Generic.Random.Internal.Generic Methods arbitraryOr :: proxy sel -> fg -> (Gen a :+ g) -> Gen a # | |
| ArbitraryOr fg fg (Nothing :: Maybe Symbol) a => ArbitraryOr fg (Gen1 f :+ g) sel (f a) # | |
Defined in Generic.Random.Internal.Generic Methods arbitraryOr :: proxy sel -> fg -> (Gen1 f :+ g) -> Gen (f a) # | |
| ArbitraryOr fg (Gen1_ f :+ g) sel (f a) # | |
Defined in Generic.Random.Internal.Generic Methods arbitraryOr :: proxy sel -> fg -> (Gen1_ f :+ g) -> Gen (f a) # | |
| ArbitraryOr fg (FieldGen n a :+ g) (Just n) a # | |
Defined in Generic.Random.Internal.Generic | |
type family SelectorName (d :: Meta) :: Maybe Symbol #
Instances
| type SelectorName (MetaSel mn su ss ds) # | |
Defined in Generic.Random.Internal.Generic | |
Instances
| Functor Weighted # | |
| Applicative Weighted # | |
| Alternative Weighted # | |