generic-random-1.2.0.0: Generic random generators

Safe HaskellNone
LanguageHaskell2010

Generic.Random.Internal.Generic

Contents

Synopsis

Random generators

genericArbitrary #

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

genericArbitraryRec #

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 Field "x" a), the generator for the first match will be picked.

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.

genericArbitraryRecG #

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

type family Weights_ (f :: * -> *) :: * where ... #

Equations

Weights_ (f :+: g) = Weights_ f :| Weights_ g 
Weights_ (M1 D _c f) = Weights_ f 
Weights_ (M1 C (MetaCons c _i _j) _f) = L c 

data a :| b #

Constructors

N a Int b 
Instances
(UniformWeight a, UniformWeight b) => UniformWeight (a :| b) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

uniformWeight :: (a :| b, Int) #

WeightBuilder a => WeightBuilder (a :| b) # 
Instance details

Defined in Generic.Random.Internal.Generic

Associated Types

type Prec (a :| b) r :: * #

Methods

(%.) :: W (First (a :| b)) -> Prec (a :| b) r -> (a :| b, Int, r) #

type Prec (a :| b) r # 
Instance details

Defined in Generic.Random.Internal.Generic

type Prec (a :| b) r = Prec a (b, Int, r)

data L (c :: Symbol) #

Constructors

L 
Instances
UniformWeight (L c) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

uniformWeight :: (L c, Int) #

WeightBuilder (L c) # 
Instance details

Defined in Generic.Random.Internal.Generic

Associated Types

type Prec (L c) r :: * #

Methods

(%.) :: W (First (L c)) -> Prec (L c) r -> (L c, Int, r) #

type Prec (L c) r # 
Instance details

Defined in Generic.Random.Internal.Generic

type Prec (L c) r = r

data Weights a #

Trees of weights assigned to constructors of type a, rescaled to obtain a probability distribution.

Two ways of constructing them.

(x1 % x2 % ... % xn % ()) :: Weights a
uniform :: Weights a

Using (%), there must be exactly as many weights as there are constructors.

uniform is equivalent to (1 % ... % 1 % ()) (automatically fills out the right number of 1s).

Constructors

Weights (Weights_ (Rep a)) Int 
Instances
WeightBuilder (Weights_ (Rep a)) => WeightBuilder' (Weights a) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

(%) :: W (First' (Weights a)) -> Prec' (Weights a) -> Weights a #

newtype W (c :: Symbol) #

Type of a single weight, tagged with the name of the associated constructor for additional compile-time checking.

((9 :: W "Leaf") % (8 :: W "Node") % ())

Constructors

W Int 
Instances
Num (W c) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

(+) :: W c -> W c -> W c #

(-) :: W c -> W c -> W c #

(*) :: W c -> W c -> W c #

negate :: W c -> W c #

abs :: W c -> W c #

signum :: W c -> W c #

fromInteger :: Integer -> W c #

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.

type family First a :: Symbol where ... #

Equations

First (a :| _b) = First a 
First (L c) = c 

type family First' w where ... #

Equations

First' (Weights a) = First (Weights_ (Rep a)) 
First' (a, Int, r) = First a 

type family Prec' w where ... #

Equations

Prec' (Weights a) = Prec (Weights_ (Rep a)) () 
Prec' (a, Int, r) = Prec a r 

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) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

(%) :: W (First' (Weights a)) -> Prec' (Weights a) -> Weights a #

WeightBuilder a => WeightBuilder' (a, Int, r) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

(%) :: W (First' (a, Int, r)) -> Prec' (a, Int, r) -> (a, Int, r) #

class WeightBuilder a where #

Minimal complete definition

(%.)

Associated Types

type Prec a r #

Methods

(%.) :: W (First a) -> Prec a r -> (a, Int, r) #

Instances
WeightBuilder () # 
Instance details

Defined in Generic.Random.Internal.Generic

Associated Types

type Prec () r :: * #

Methods

(%.) :: W (First ()) -> Prec () r -> ((), Int, r) #

WeightBuilder (L c) # 
Instance details

Defined in Generic.Random.Internal.Generic

Associated Types

type Prec (L c) r :: * #

Methods

(%.) :: W (First (L c)) -> Prec (L c) r -> (L c, Int, r) #

WeightBuilder a => WeightBuilder (a :| b) # 
Instance details

Defined in Generic.Random.Internal.Generic

Associated Types

type Prec (a :| b) r :: * #

Methods

(%.) :: W (First (a :| b)) -> Prec (a :| b) r -> (a :| b, Int, r) #

class UniformWeight a where #

Minimal complete definition

uniformWeight

Methods

uniformWeight :: (a, Int) #

Instances
UniformWeight () # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

uniformWeight :: ((), Int) #

UniformWeight (L c) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

uniformWeight :: (L c, Int) #

(UniformWeight a, UniformWeight b) => UniformWeight (a :| b) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

uniformWeight :: (a :| b, Int) #

class UniformWeight (Weights_ f) => UniformWeight_ f #

Instances
UniformWeight (Weights_ f) => UniformWeight_ f # 
Instance details

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 # 
Instance details

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) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

generators :: Options s g -> GeneratorsOf (Options s g) #

type SetGens g (Options s _g) # 
Instance details

Defined in Generic.Random.Internal.Generic

type SetGens g (Options s _g) = Options s g
type GeneratorsOf (Options _s g) # 
Instance details

Defined in Generic.Random.Internal.Generic

type GeneratorsOf (Options _s g) = g
type SizingOf (Options s _g) # 
Instance details

Defined in Generic.Random.Internal.Generic

type SizingOf (Options s _g) = s

unsizedOpts :: UnsizedOpts #

Default options for unsized generators.

sizedOpts :: SizedOpts #

Default options for sized generators.

sizedOptsDef :: SizedOptsDef #

Default options overriding the list generator using listOf'.

data Sizing #

Whether to decrease the size parameter before generating fields.

Constructors

Sized 
Unsized 

type family SizingOf opts :: Sizing #

Instances
type SizingOf (Options s _g) # 
Instance details

Defined in Generic.Random.Internal.Generic

type SizingOf (Options s _g) = s

proxySizing :: opts -> Proxy (SizingOf opts) #

data a :+ b infixr 1 #

Heterogeneous list of generators.

Constructors

a :+ b infixr 1 
Instances
ArbitraryOr fg g sel a => ArbitraryOr fg (b :+ g) sel a # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

arbitraryOr :: proxy sel -> fg -> (b :+ g) -> Gen a #

ArbitraryOr fg (Gen a :+ g) sel a # 
Instance details

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) # 
Instance details

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) # 
Instance details

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 # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

arbitraryOr :: proxy (Just n) -> fg -> (FieldGen n a :+ g) -> Gen a #

type family GeneratorsOf opts :: Type #

Instances
type GeneratorsOf (Options _s g) # 
Instance details

Defined in Generic.Random.Internal.Generic

type GeneratorsOf (Options _s g) = g

class HasGenerators opts where #

Minimal complete definition

generators

Methods

generators :: opts -> GeneratorsOf opts #

Instances
HasGenerators (Options s g) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

generators :: Options s g -> GeneratorsOf (Options s g) #

setGenerators :: genList -> Options s g0 -> Options s genList #

type family SetGens (g :: Type) opts #

Instances
type SetGens g (Options s _g) # 
Instance details

Defined in Generic.Random.Internal.Generic

type SetGens g (Options s _g) = Options s g

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 # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

arbitraryOr :: proxy (Just n) -> fg -> (FieldGen n a :+ g) -> Gen a #

fieldGen :: proxy s -> Gen a -> FieldGen s a #

Field constructor with the field name given via a proxy.

newtype Gen1 f #

Generators for containers of kind * -> *, parameterized by the generator for each element.

Constructors

Gen1 

Fields

Instances
ArbitraryOr fg fg (Nothing :: Maybe Symbol) a => ArbitraryOr fg (Gen1 f :+ g) sel (f a) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

arbitraryOr :: proxy sel -> fg -> (Gen1 f :+ g) -> Gen (f a) #

newtype Gen1_ f #

Generators for unary type constructors that are not containers.

Constructors

Gen1_ 

Fields

Instances
ArbitraryOr fg (Gen1_ f :+ g) sel (f a) # 
Instance details

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.

listOf' :: Gen a -> Gen [a] #

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).

geom :: Int -> Gen Int #

Geometric distribution of parameter 1/(sqrt n + 1) (n >= 0).

class GA opts f where #

Generic Arbitrary

Minimal complete definition

ga

Methods

ga :: opts -> Weights_ f -> Int -> Gen (f p) #

Instances
(GASum opts f, GASum opts g) => GA opts (f :+: g) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

ga :: opts -> Weights_ (f :+: g) -> Int -> Gen ((f :+: g) p) #

GAProduct (SizingOf opts) opts f => GA opts (M1 C c f) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

ga :: opts -> Weights_ (M1 C c f) -> Int -> Gen (M1 C c f p) #

GA opts f => GA opts (M1 D c f) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

ga :: opts -> Weights_ (M1 D c f) -> Int -> Gen (M1 D c f p) #

class (Generic a, GA opts (Rep a)) => GArbitrary opts a #

Generic Arbitrary

Instances
(Generic a, GA opts (Rep a)) => GArbitrary opts a # 
Instance details

Defined in Generic.Random.Internal.Generic

gaSum' :: GASum opts f => opts -> Weights_ f -> Int -> Gen (f p) #

class GASum opts f where #

Minimal complete definition

gaSum

Methods

gaSum :: opts -> Int -> Weights_ f -> Gen (f p) #

Instances
(GASum opts f, GASum opts g) => GASum opts (f :+: g) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

gaSum :: opts -> Int -> Weights_ (f :+: g) -> Gen ((f :+: g) p) #

GAProduct (SizingOf opts) opts f => GASum opts (M1 i c f) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

gaSum :: opts -> Int -> Weights_ (M1 i c f) -> Gen (M1 i c f p) #

class GAProduct (s :: Sizing) opts f where #

Minimal complete definition

gaProduct

Methods

gaProduct :: proxys s -> opts -> Gen (f p) #

Instances
GAProduct' opts f => GAProduct Unsized opts (f :: k -> *) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

gaProduct :: proxys Unsized -> opts -> Gen (f p) #

(GAProduct' opts f, KnownNat (Arity f)) => GAProduct Sized opts (f :: k -> *) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

gaProduct :: proxys Sized -> opts -> Gen (f p) #

GAProduct Sized opts (U1 :: k -> *) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

gaProduct :: proxys Sized -> opts -> Gen (U1 p) #

GAProduct' opts (S1 d f) => GAProduct Sized opts (S1 d f :: k -> *) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

gaProduct :: proxys Sized -> opts -> Gen (S1 d f p) #

class GAProduct' opts f where #

Minimal complete definition

gaProduct'

Methods

gaProduct' :: opts -> Gen (f p) #

Instances
GAProduct' opts (U1 :: k -> *) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

gaProduct' :: opts -> Gen (U1 p) #

(GAProduct' opts f, GAProduct' opts g) => GAProduct' opts (f :*: g :: k -> *) # 
Instance details

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 -> *) # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

gaProduct' :: opts -> Gen (S1 d (K1 i c) p) #

type family Arity f :: Nat where ... #

Equations

Arity (f :*: g) = Arity f + Arity g 
Arity (M1 _i _c _f) = 1 

class ArbitraryOr (fullGenList :: Type) (genList :: Type) (sel :: Maybe Symbol) a where #

Minimal complete definition

arbitraryOr

Methods

arbitraryOr :: proxy sel -> fullGenList -> genList -> Gen a #

Instances
Arbitrary a => ArbitraryOr fg () sel a # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

arbitraryOr :: proxy sel -> fg -> () -> Gen a #

ArbitraryOr fg g sel a => ArbitraryOr fg (b :+ g) sel a # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

arbitraryOr :: proxy sel -> fg -> (b :+ g) -> Gen a #

ArbitraryOr fg (Gen a :+ g) sel a # 
Instance details

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) # 
Instance details

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) # 
Instance details

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 # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

arbitraryOr :: proxy (Just n) -> fg -> (FieldGen n a :+ g) -> Gen a #

type family SelectorName (d :: Meta) :: Maybe Symbol #

Instances
type SelectorName (MetaSel mn su ss ds) # 
Instance details

Defined in Generic.Random.Internal.Generic

type SelectorName (MetaSel mn su ss ds) = mn

newtype Weighted a #

Constructors

Weighted (Maybe (Int -> Gen a, Int)) 
Instances
Functor Weighted # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

fmap :: (a -> b) -> Weighted a -> Weighted b #

(<$) :: a -> Weighted b -> Weighted a #

Applicative Weighted # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

pure :: a -> Weighted a #

(<*>) :: Weighted (a -> b) -> Weighted a -> Weighted b #

liftA2 :: (a -> b -> c) -> Weighted a -> Weighted b -> Weighted c #

(*>) :: Weighted a -> Weighted b -> Weighted b #

(<*) :: Weighted a -> Weighted b -> Weighted a #

Alternative Weighted # 
Instance details

Defined in Generic.Random.Internal.Generic

Methods

empty :: Weighted a #

(<|>) :: Weighted a -> Weighted a -> Weighted a #

some :: Weighted a -> Weighted [a] #

many :: Weighted a -> Weighted [a] #

liftGen :: Gen a -> Weighted a #