-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Generic random generators -- -- For more information -- --
-- 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. genericArbitrary :: (GArbitrary UnsizedOpts a) => Weights a -> Gen a -- | Pick every constructor with equal probability. Equivalent to -- genericArbitrary uniform. -- --
-- genericArbitraryU :: Gen a --genericArbitraryU :: (GArbitrary UnsizedOpts a, GUniformWeight a) => Gen a -- | arbitrary for types with one constructor. Equivalent to -- genericArbitraryU, with a stricter type. -- --
-- genericArbitrarySingle :: Gen a --genericArbitrarySingle :: (GArbitrary UnsizedOpts a, Weights_ (Rep a) ~ L c0) => 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. genericArbitraryRec :: (GArbitrary SizedOptsDef a) => Weights a -> Gen a -- | genericArbitrary with explicit generators. -- --
-- 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 ---- --
-- (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). data Weights a Weights :: (Weights_ (Rep a)) -> Int -> Weights a -- | Type of a single weight, tagged with the name of the associated -- constructor for additional compile-time checking. -- --
-- ((9 :: W "Leaf") % (8 :: W "Node") % ()) --newtype W (c :: Symbol) W :: Int -> W -- | A smart constructor to specify a custom distribution. It can be -- omitted for the % operator is overloaded to insert it. weights :: (Weights_ (Rep a), Int, ()) -> Weights a -- | Uniform distribution. uniform :: UniformWeight_ (Rep a) => Weights a class WeightBuilder' w -- | A binary constructor for building up trees of weights. (%) :: WeightBuilder' w => W (First' w) -> Prec' w -> w class WeightBuilder a where { type family Prec a r; } (%.) :: WeightBuilder a => W (First a) -> Prec a r -> (a, Int, r) class UniformWeight a uniformWeight :: UniformWeight a => (a, Int) class UniformWeight (Weights_ f) => UniformWeight_ f -- | Derived uniform distribution of constructors for a. class UniformWeight_ (Rep a) => GUniformWeight a -- | Type-level options for GArbitrary. newtype Options (s :: Sizing) (genList :: Type) Options :: genList -> Options [_generators] :: Options -> genList -- | Default options for unsized generators. unsizedOpts :: UnsizedOpts -- | Default options for sized generators. sizedOpts :: SizedOpts -- | Default options overriding the list generator using listOf'. sizedOptsDef :: SizedOptsDef -- | Whether to decrease the size parameter before generating fields. data Sizing Sized :: Sizing Unsized :: Sizing type UnsizedOpts = Options 'Unsized () type SizedOpts = Options 'Sized () type SizedOptsDef = Options 'Sized (Gen1 [] :+ ()) proxySizing :: opts -> Proxy (SizingOf opts) setSized :: Options s g -> Options 'Sized g setUnsized :: Options s g -> Options 'Unsized g -- | Heterogeneous list of generators. data a (:+) b (:+) :: a -> b -> (:+) a b class HasGenerators opts generators :: HasGenerators opts => opts -> GeneratorsOf opts setGenerators :: genList -> Options s g0 -> Options s genList -- | A generator which overrides a specific field named s. -- -- Available only for base >= 4.9. newtype FieldGen (s :: Symbol) a FieldGen :: Gen a -> FieldGen a [unFieldGen] :: FieldGen a -> Gen a -- | Field constructor with the field name given via a proxy. fieldGen :: proxy s -> Gen a -> FieldGen s a -- | Generators for containers of kind * -> *, parameterized by -- the generator for each element. newtype Gen1 f Gen1 :: (forall a. Gen a -> Gen (f a)) -> Gen1 f [unGen1] :: Gen1 f -> forall a. Gen a -> Gen (f a) -- | Generators for unary type constructors that are not containers. newtype Gen1_ f Gen1_ :: (forall a. Gen (f a)) -> Gen1_ f [unGen1_] :: Gen1_ f -> forall a. Gen (f a) -- | An alternative to vectorOf that divides the size parameter by -- the length of the list. vectorOf' :: Int -> 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). listOf' :: 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). listOf1' :: Gen a -> Gen [a] -- | Geometric distribution of parameter 1/(sqrt n + 1) (n -- >= 0). geom :: Int -> Gen Int -- | Generic Arbitrary class GA opts f ga :: GA opts f => opts -> Weights_ f -> Int -> Gen (f p) -- | Generic Arbitrary 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 gaSum :: GASum opts f => opts -> Int -> Weights_ f -> Gen (f p) class GAProduct (s :: Sizing) opts f gaProduct :: GAProduct s opts f => proxys s -> opts -> Gen (f p) class GAProduct' opts f gaProduct' :: GAProduct' opts f => opts -> Gen (f p) class ArbitraryOr (fullGenList :: Type) (genList :: Type) (sel :: Maybe Symbol) a arbitraryOr :: ArbitraryOr fullGenList genList sel a => proxy sel -> fullGenList -> genList -> Gen a newtype Weighted a Weighted :: (Maybe (Int -> Gen a, Int)) -> Weighted a liftGen :: Gen a -> Weighted a instance GHC.Base.Functor Generic.Random.Internal.Generic.Weighted instance GHC.Num.Num (Generic.Random.Internal.Generic.W c) instance GHC.Base.Applicative Generic.Random.Internal.Generic.Weighted instance GHC.Base.Alternative Generic.Random.Internal.Generic.Weighted instance (Generic.Random.Internal.Generic.HasGenerators opts, Generic.Random.Internal.Generic.ArbitraryOr gs gs (Generic.Random.Internal.Generic.SelectorName d) c, gs ~ Generic.Random.Internal.Generic.GeneratorsOf opts) => Generic.Random.Internal.Generic.GAProduct' opts (GHC.Generics.S1 d (GHC.Generics.K1 i c)) instance Generic.Random.Internal.Generic.ArbitraryOr fg (Test.QuickCheck.Gen.Gen a Generic.Random.Internal.Generic.:+ g) sel a instance Generic.Random.Internal.Generic.ArbitraryOr fg g sel a => Generic.Random.Internal.Generic.ArbitraryOr fg (b Generic.Random.Internal.Generic.:+ g) sel a instance Test.QuickCheck.Arbitrary.Arbitrary a => Generic.Random.Internal.Generic.ArbitraryOr fg () sel a instance Generic.Random.Internal.Generic.ArbitraryOr fg (Generic.Random.Internal.Generic.FieldGen n a Generic.Random.Internal.Generic.:+ g) ('GHC.Base.Just n) a instance forall k fg (f :: k -> *) g (sel :: GHC.Base.Maybe GHC.Types.Symbol) (a :: k). Generic.Random.Internal.Generic.ArbitraryOr fg (Generic.Random.Internal.Generic.Gen1_ f Generic.Random.Internal.Generic.:+ g) sel (f a) instance Generic.Random.Internal.Generic.ArbitraryOr fg fg 'GHC.Base.Nothing a => Generic.Random.Internal.Generic.ArbitraryOr fg (Generic.Random.Internal.Generic.Gen1 f Generic.Random.Internal.Generic.:+ g) sel (f a) instance forall k opts (f :: k -> *). (Generic.Random.Internal.Generic.GAProduct' opts f, GHC.TypeNats.KnownNat (Generic.Random.Internal.Generic.Arity f)) => Generic.Random.Internal.Generic.GAProduct 'Generic.Random.Internal.Generic.Sized opts f instance forall k opts (f :: k -> *). Generic.Random.Internal.Generic.GAProduct' opts f => Generic.Random.Internal.Generic.GAProduct 'Generic.Random.Internal.Generic.Unsized opts f instance forall k opts (d :: GHC.Generics.Meta) (f :: k -> *). Generic.Random.Internal.Generic.GAProduct' opts (GHC.Generics.S1 d f) => Generic.Random.Internal.Generic.GAProduct 'Generic.Random.Internal.Generic.Sized opts (GHC.Generics.S1 d f) instance Generic.Random.Internal.Generic.GAProduct' opts GHC.Generics.U1 instance forall k opts (f :: k -> *) (g :: k -> *). (Generic.Random.Internal.Generic.GAProduct' opts f, Generic.Random.Internal.Generic.GAProduct' opts g) => Generic.Random.Internal.Generic.GAProduct' opts (f GHC.Generics.:*: g) instance Generic.Random.Internal.Generic.GAProduct (Generic.Random.Internal.Generic.SizingOf opts) opts f => Generic.Random.Internal.Generic.GA opts (GHC.Generics.M1 GHC.Generics.C c f) instance Generic.Random.Internal.Generic.GAProduct (Generic.Random.Internal.Generic.SizingOf opts) opts f => Generic.Random.Internal.Generic.GASum opts (GHC.Generics.M1 i c f) instance Generic.Random.Internal.Generic.GAProduct 'Generic.Random.Internal.Generic.Sized opts GHC.Generics.U1 instance (Generic.Random.Internal.Generic.GASum opts f, Generic.Random.Internal.Generic.GASum opts g) => Generic.Random.Internal.Generic.GA opts (f GHC.Generics.:+: g) instance (Generic.Random.Internal.Generic.GASum opts f, Generic.Random.Internal.Generic.GASum opts g) => Generic.Random.Internal.Generic.GASum opts (f GHC.Generics.:+: g) instance (GHC.Generics.Generic a, Generic.Random.Internal.Generic.GA opts (GHC.Generics.Rep a)) => Generic.Random.Internal.Generic.GArbitrary opts a instance Generic.Random.Internal.Generic.GA opts f => Generic.Random.Internal.Generic.GA opts (GHC.Generics.M1 GHC.Generics.D c f) instance Generic.Random.Internal.Generic.HasGenerators (Generic.Random.Internal.Generic.Options s g) instance Generic.Random.Internal.Generic.UniformWeight_ (GHC.Generics.Rep a) => Generic.Random.Internal.Generic.GUniformWeight a instance Generic.Random.Internal.Generic.UniformWeight (Generic.Random.Internal.Generic.Weights_ f) => Generic.Random.Internal.Generic.UniformWeight_ f instance (Generic.Random.Internal.Generic.UniformWeight a, Generic.Random.Internal.Generic.UniformWeight b) => Generic.Random.Internal.Generic.UniformWeight (a Generic.Random.Internal.Generic.:| b) instance Generic.Random.Internal.Generic.UniformWeight (Generic.Random.Internal.Generic.L c) instance Generic.Random.Internal.Generic.UniformWeight () instance Generic.Random.Internal.Generic.WeightBuilder (Generic.Random.Internal.Generic.Weights_ (GHC.Generics.Rep a)) => Generic.Random.Internal.Generic.WeightBuilder' (Generic.Random.Internal.Generic.Weights a) instance Generic.Random.Internal.Generic.WeightBuilder a => Generic.Random.Internal.Generic.WeightBuilder' (a, GHC.Types.Int, r) instance Generic.Random.Internal.Generic.WeightBuilder a => Generic.Random.Internal.Generic.WeightBuilder (a Generic.Random.Internal.Generic.:| b) instance Generic.Random.Internal.Generic.WeightBuilder (Generic.Random.Internal.Generic.L c) instance Generic.Random.Internal.Generic.WeightBuilder () module Generic.Random.Internal.BaseCase -- | Decrease size to ensure termination for recursive types, looking for -- base cases once the size reaches 0. -- --
-- genericArbitrary' (17 % 19 % 23 % ()) :: Gen a ---- -- N.B.: This replaces fields of type [t] with -- listOf' arbitrary. genericArbitrary' :: (GArbitrary SizedOptsDef a, BaseCase a) => Weights a -> Gen a -- | Equivalent to genericArbitrary' uniform. -- --
-- genericArbitraryU :: Gen a ---- -- N.B.: This replaces fields of type [t] with -- listOf' arbitrary. genericArbitraryU' :: (GArbitrary SizedOptsDef a, BaseCase a, GUniformWeight a) => Gen a -- | Run the first generator if the size is positive. Run the second if the -- size is zero. -- --
-- defaultGen `withBaseCase` baseCaseGen --withBaseCase :: Gen a -> Gen a -> Gen a -- | Find a base case of type a with maximum depth z, -- recursively using BaseCaseSearch instances to search deeper -- levels. -- -- y is the depth of a base case, if found. -- -- e is the original type the search started with, that -- a appears in. It is used for error reporting. class BaseCaseSearch (a :: *) (z :: Nat) (y :: Maybe Nat) (e :: *) baseCaseSearch :: BaseCaseSearch a z y e => prox y -> proxy '(z, e) -> IfM y Gen Proxy a class BaseCaseSearching_ a z y baseCaseSearching_ :: BaseCaseSearching_ a z y => proxy y -> proxy2 '(z, a) -> IfM y Gen Proxy a -> Gen a -- | Progressively increase the depth bound for BaseCaseSearch. class BaseCaseSearching a z baseCaseSearching :: BaseCaseSearching a z => proxy '(z, a) -> Gen a -- | Custom instances can override the default behavior. class BaseCase a -- | Generator of base cases. baseCase :: BaseCase a => Gen a -- | Overlappable type (==) m n = IsEQ (CmpNat m n) type Max m n = MaxOf (CmpNat m n) m n type Min m n = MinOf (CmpNat m n) m n class Alternative (IfM y Weighted Proxy) => GBCS (f :: k -> *) (z :: Nat) (y :: Maybe Nat) (e :: *) gbcs :: GBCS f z y e => prox y -> proxy '(z, e) -> IfM y Weighted Proxy (f p) class Alternative (IfM (yf ||? yg) Weighted Proxy) => GBCSSum f g z e yf yg gbcsSum :: GBCSSum f g z e yf yg => prox '(yf, yg) -> proxy '(z, e) -> IfM yf Weighted Proxy (f p) -> IfM yg Weighted Proxy (g p) -> IfM (yf ||? yg) Weighted Proxy ((f :+: g) p) class GBCSSumCompare f g z e o gbcsSumCompare :: GBCSSumCompare f g z e o => proxy0 o -> proxy '(z, e) -> Weighted (f p) -> Weighted (g p) -> Weighted ((f :+: g) p) class Alternative (IfM (yf &&? yg) Weighted Proxy) => GBCSProduct f g z e yf yg gbcsProduct :: GBCSProduct f g z e yf yg => prox '(yf, yg) -> proxy '(z, e) -> IfM yf Weighted Proxy (f p) -> IfM yg Weighted Proxy (g p) -> IfM (yf &&? yg) Weighted Proxy ((f :*: g) p) class IsMaybe b ifMmap :: IsMaybe b => proxy b -> (c a -> c' a') -> (d a -> d' a') -> IfM b c d a -> IfM b c' d' a' ifM :: IsMaybe b => proxy b -> c a -> d a -> IfM b c d a class GBaseCaseSearch a z y e gBaseCaseSearch :: GBaseCaseSearch a z y e => prox y -> proxy '(z, e) -> IfM y Gen Proxy a instance Generic.Random.Internal.BaseCase.GBaseCaseSearch a z y e => Generic.Random.Internal.BaseCase.BaseCaseSearch a z y e instance (GHC.Generics.Generic a, Generic.Random.Internal.BaseCase.GBCS (GHC.Generics.Rep a) z y e, Generic.Random.Internal.BaseCase.IsMaybe y) => Generic.Random.Internal.BaseCase.GBaseCaseSearch a z y e instance forall t1 (t2 :: t1). Generic.Random.Internal.BaseCase.IsMaybe ('GHC.Base.Just t2) instance Generic.Random.Internal.BaseCase.IsMaybe 'GHC.Base.Nothing instance (Generic.Random.Internal.BaseCase.BaseCaseSearch c (z GHC.TypeNats.- 1) y e, (z Generic.Random.Internal.BaseCase.== 0) ~ 'GHC.Types.False, GHC.Base.Alternative (Generic.Random.Internal.BaseCase.IfM y Generic.Random.Internal.Generic.Weighted Data.Proxy.Proxy), Generic.Random.Internal.BaseCase.IsMaybe y) => Generic.Random.Internal.BaseCase.GBCS (GHC.Generics.K1 i c) z y e instance forall k (f :: k -> *) (g :: k -> *) (z :: GHC.Types.Nat) e (yf :: GHC.Base.Maybe GHC.Types.Nat) (yg :: GHC.Base.Maybe GHC.Types.Nat) (y :: GHC.Base.Maybe GHC.Types.Nat). (Generic.Random.Internal.BaseCase.GBCSProduct f g z e yf yg, Generic.Random.Internal.BaseCase.GBCS f z yf e, Generic.Random.Internal.BaseCase.GBCS g z yg e, y ~ (yf Generic.Random.Internal.BaseCase.&&? yg)) => Generic.Random.Internal.BaseCase.GBCS (f GHC.Generics.:*: g) z y e instance forall k1 k2 k3 (yf :: GHC.Base.Maybe GHC.Types.Nat) (yg :: GHC.Base.Maybe GHC.Types.Nat) (f :: k3 -> *) (g :: k3 -> *) (z :: k2) (e :: k1). (yf Generic.Random.Internal.BaseCase.&&? yg) ~ 'GHC.Base.Nothing => Generic.Random.Internal.BaseCase.GBCSProduct f g z e yf yg instance forall k1 k2 k3 (f :: k3 -> *) (g :: k3 -> *) (z :: k2) (e :: k1) (m :: GHC.Types.Nat) (n :: GHC.Types.Nat). Generic.Random.Internal.BaseCase.GBCSProduct f g z e ('GHC.Base.Just m) ('GHC.Base.Just n) instance forall k1 k2 k3 (f :: k3 -> *) (g :: k3 -> *) (z :: k2) (e :: k1) (m :: GHC.Types.Nat) (n :: GHC.Types.Nat). Generic.Random.Internal.BaseCase.GBCSSumCompare f g z e (GHC.TypeNats.CmpNat m n) => Generic.Random.Internal.BaseCase.GBCSSum f g z e ('GHC.Base.Just m) ('GHC.Base.Just n) instance forall k1 k2 k3 (f :: k3 -> *) (g :: k3 -> *) (z :: k2) (e :: k1). Generic.Random.Internal.BaseCase.GBCSSumCompare f g z e 'GHC.Types.EQ instance forall k1 k2 k3 (f :: k3 -> *) (g :: k3 -> *) (z :: k2) (e :: k1). Generic.Random.Internal.BaseCase.GBCSSumCompare f g z e 'GHC.Types.LT instance forall k1 k2 k3 (f :: k3 -> *) (g :: k3 -> *) (z :: k2) (e :: k1). Generic.Random.Internal.BaseCase.GBCSSumCompare f g z e 'GHC.Types.GT instance forall k (f :: k -> *) (g :: k -> *) (z :: GHC.Types.Nat) e (yf :: GHC.Base.Maybe GHC.Types.Nat) (yg :: GHC.Base.Maybe GHC.Types.Nat) (y :: GHC.Base.Maybe GHC.Types.Nat). (Generic.Random.Internal.BaseCase.GBCSSum f g z e yf yg, Generic.Random.Internal.BaseCase.GBCS f z yf e, Generic.Random.Internal.BaseCase.GBCS g z yg e, y ~ (yf Generic.Random.Internal.BaseCase.||? yg)) => Generic.Random.Internal.BaseCase.GBCS (f GHC.Generics.:+: g) z y e instance forall k1 k2 k3 (f :: k3 -> *) (g :: k3 -> *) (z :: k2) (e :: k1). Generic.Random.Internal.BaseCase.GBCSSum f g z e 'GHC.Base.Nothing 'GHC.Base.Nothing instance forall k1 k2 k3 (f :: k3 -> *) (g :: k3 -> *) (z :: k2) (e :: k1) (m :: GHC.Types.Nat). Generic.Random.Internal.BaseCase.GBCSSum f g z e ('GHC.Base.Just m) 'GHC.Base.Nothing instance forall k1 k2 k3 (f :: k3 -> *) (g :: k3 -> *) (z :: k2) (e :: k1) (n :: GHC.Types.Nat). Generic.Random.Internal.BaseCase.GBCSSum f g z e 'GHC.Base.Nothing ('GHC.Base.Just n) instance forall k (f :: k -> *) (z :: GHC.Types.Nat) (y :: GHC.Base.Maybe GHC.Types.Nat) e i (c :: GHC.Generics.Meta). Generic.Random.Internal.BaseCase.GBCS f z y e => Generic.Random.Internal.BaseCase.GBCS (GHC.Generics.M1 i c f) z y e instance y ~ 'GHC.Base.Nothing => Generic.Random.Internal.BaseCase.GBCS (GHC.Generics.K1 i c) 0 y e instance y ~ 'GHC.Base.Just 0 => Generic.Random.Internal.BaseCase.GBCS GHC.Generics.U1 z y e instance forall k (f :: k -> *) e (y :: GHC.Base.Maybe GHC.Types.Nat) (z :: GHC.Types.Nat). ((TypeError ...), GHC.Base.Alternative (Generic.Random.Internal.BaseCase.IfM y Generic.Random.Internal.Generic.Weighted Data.Proxy.Proxy)) => Generic.Random.Internal.BaseCase.GBCS f z y e instance y ~ 'GHC.Base.Just 0 => Generic.Random.Internal.BaseCase.BaseCaseSearch GHC.Types.Char z y e instance y ~ 'GHC.Base.Just 0 => Generic.Random.Internal.BaseCase.BaseCaseSearch GHC.Types.Int z y e instance y ~ 'GHC.Base.Just 0 => Generic.Random.Internal.BaseCase.BaseCaseSearch GHC.Integer.Type.Integer z y e instance y ~ 'GHC.Base.Just 0 => Generic.Random.Internal.BaseCase.BaseCaseSearch GHC.Types.Float z y e instance y ~ 'GHC.Base.Just 0 => Generic.Random.Internal.BaseCase.BaseCaseSearch GHC.Types.Double z y e instance y ~ 'GHC.Base.Just 0 => Generic.Random.Internal.BaseCase.BaseCaseSearch GHC.Types.Word z y e instance y ~ 'GHC.Base.Just 0 => Generic.Random.Internal.BaseCase.BaseCaseSearch () z y e instance y ~ 'GHC.Base.Just 0 => Generic.Random.Internal.BaseCase.BaseCaseSearch GHC.Types.Bool z y e instance y ~ 'GHC.Base.Just 0 => Generic.Random.Internal.BaseCase.BaseCaseSearch [a] z y e instance y ~ 'GHC.Base.Just 0 => Generic.Random.Internal.BaseCase.BaseCaseSearch GHC.Types.Ordering z y e instance (Generic.Random.Internal.BaseCase.BaseCaseSearch a z y a, Generic.Random.Internal.BaseCase.BaseCaseSearching_ a z y) => Generic.Random.Internal.BaseCase.BaseCaseSearching a z instance forall t k a (z :: k) (m :: t). Generic.Random.Internal.BaseCase.BaseCaseSearching_ a z ('GHC.Base.Just m) instance Generic.Random.Internal.BaseCase.BaseCaseSearching a (z GHC.TypeNats.+ 1) => Generic.Random.Internal.BaseCase.BaseCaseSearching_ a z 'GHC.Base.Nothing instance Generic.Random.Internal.BaseCase.BaseCaseSearching a 0 => Generic.Random.Internal.BaseCase.BaseCase a -- | Simple GHC.Generics-based arbitrary generators. -- -- For more information: -- --
-- 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. genericArbitrary :: (GArbitrary UnsizedOpts a) => Weights a -> Gen a -- | Pick every constructor with equal probability. Equivalent to -- genericArbitrary uniform. -- --
-- genericArbitraryU :: Gen a --genericArbitraryU :: (GArbitrary UnsizedOpts a, GUniformWeight a) => Gen a -- | arbitrary for types with one constructor. Equivalent to -- genericArbitraryU, with a stricter type. -- --
-- genericArbitrarySingle :: Gen a --genericArbitrarySingle :: (GArbitrary UnsizedOpts a, Weights_ (Rep a) ~ L c0) => 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. genericArbitraryRec :: (GArbitrary SizedOptsDef a) => Weights a -> 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 ---- -- N.B.: This replaces fields of type [t] with -- listOf' arbitrary. genericArbitrary' :: (GArbitrary SizedOptsDef a, BaseCase a) => Weights a -> Gen a -- | Equivalent to genericArbitrary' uniform. -- --
-- genericArbitraryU :: Gen a ---- -- N.B.: This replaces fields of type [t] with -- listOf' arbitrary. genericArbitraryU' :: (GArbitrary SizedOptsDef a, BaseCase a, GUniformWeight a) => Gen a -- | genericArbitrary with explicit generators. -- --
-- 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 ---- --
-- defaultGen `withBaseCase` baseCaseGen --withBaseCase :: Gen a -> Gen a -> Gen a -- | Custom instances can override the default behavior. class BaseCase a -- | Generator of base cases. baseCase :: BaseCase a => Gen 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). data Weights a -- | Type of a single weight, tagged with the name of the associated -- constructor for additional compile-time checking. -- --
-- ((9 :: W "Leaf") % (8 :: W "Node") % ()) --data W (c :: Symbol) -- | A binary constructor for building up trees of weights. (%) :: WeightBuilder' w => W (First' w) -> Prec' w -> w infixr 1 % -- | Uniform distribution. uniform :: UniformWeight_ (Rep a) => Weights a -- | Type-level options for GArbitrary. data Options (s :: Sizing) (genList :: Type) type SizedOpts = Options 'Sized () -- | Default options for sized generators. sizedOpts :: SizedOpts type SizedOptsDef = Options 'Sized (Gen1 [] :+ ()) -- | Default options overriding the list generator using listOf'. sizedOptsDef :: SizedOptsDef type UnsizedOpts = Options 'Unsized () -- | Default options for unsized generators. unsizedOpts :: UnsizedOpts -- | Whether to decrease the size parameter before generating fields. data Sizing Sized :: Sizing Unsized :: Sizing setSized :: Options s g -> Options 'Sized g setUnsized :: Options s g -> Options 'Unsized g -- | Heterogeneous list of generators. data a (:+) b (:+) :: a -> b -> (:+) a b -- | A generator which overrides a specific field named s. -- -- Available only for base >= 4.9. newtype FieldGen (s :: Symbol) a FieldGen :: Gen a -> FieldGen a [unFieldGen] :: FieldGen a -> Gen a -- | Field constructor with the field name given via a proxy. fieldGen :: proxy s -> Gen a -> FieldGen s a -- | Generators for containers of kind * -> *, parameterized by -- the generator for each element. newtype Gen1 f Gen1 :: (forall a. Gen a -> Gen (f a)) -> Gen1 f [unGen1] :: Gen1 f -> forall a. Gen a -> Gen (f a) -- | Generators for unary type constructors that are not containers. newtype Gen1_ f Gen1_ :: (forall a. Gen (f a)) -> Gen1_ f [unGen1_] :: Gen1_ f -> forall a. Gen (f a) setGenerators :: genList -> Options s g0 -> Options s genList -- | Generic Arbitrary class (Generic a, GA opts (Rep a)) => GArbitrary opts a -- | Derived uniform distribution of constructors for a. class UniformWeight_ (Rep a) => GUniformWeight 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). listOf' :: 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). listOf1' :: Gen a -> Gen [a] -- | An alternative to vectorOf that divides the size parameter by -- the length of the list. vectorOf' :: Int -> Gen a -> Gen [a] -- | Generic implementations of QuickCheck's arbitrary. -- --
-- data Tree a = Leaf a | Node (Tree a) (Tree a) -- deriving Generic ---- -- Pick an arbitrary implementation, specifying the required -- distribution of data constructors. -- --
-- instance Arbitrary a => Arbitrary (Tree a) where -- arbitrary = genericArbitrary (9 % 8 % ()) ---- -- arbitrary :: Gen (Tree a) picks a Leaf with -- probability 9/17, or a Node with probability 8/17, and -- recursively fills their fields with arbitrary. -- -- For Tree, genericArbitrary produces code equivalent to -- the following: -- --
-- genericArbitrary :: Arbitrary a => Weights (Tree a) -> Gen (Tree a) -- genericArbitrary (x % y % ()) = -- frequency -- [ (x, Leaf <$> arbitrary) -- , (y, Node <$> arbitrary <*> arbitrary) -- ] ---- --
-- ((x :: W "Leaf") % (y :: W "Node") % ()) :: Weights (Tree a) -- ( x % (y :: W "Node") % ()) :: Weights (Tree a) ---- -- This will not. -- --
-- ((x :: W "Node") % y % ()) :: Weights (Tree a) -- -- Requires an order of constructors different from the definition of the Tree type. -- -- ( x % y % z % ()) :: Weights (Tree a) -- -- Doesn't have the right number of weights. ---- --
-- instance Arbitrary a => Arbitrary (Tree a) where -- arbitrary = genericArbitraryRec (1 % 2 % ()) -- `withBaseCase` (Leaf <$> arbitrary) ---- -- That is equivalent to the following definition. Note the resize -- modifier. -- --
-- arbitrary :: Arbitrary a => Gen (Tree a) -- arbitrary = sized $ \n -> -- -- "if" condition from withBaseCase -- if n == 0 then -- Leaf <$> arbitrary -- else -- -- genericArbitraryRec -- frequency -- [ (1, resize (max 0 (n - 1)) (Leaf <$> arbitrary)) -- , (2, resize (n `div` 2) (Node <$> arbitrary <*> arbitrary)) -- ] ---- -- The resizing strategy is as follows: the size parameter of -- Gen is divided among the fields of the chosen constructor, or -- decreases by one if the constructor is unary. withBaseCase -- defG baseG is equal to defG as long as the size -- parameter is nonzero, and it becomes baseG once the size -- reaches zero. This combination generally ensures that the number of -- constructors remains close to the initial size parameter passed to -- Gen. -- --
-- {-# LANGUAGE FlexibleInstances #-}
--
-- instance Arbitrary (Tree ()) where
-- arbitrary = genericArbitrary' (1 % 2 % ())
--
--
-- The above instance will infer the value Leaf () as a base
-- case.
--
-- To discover values of type Tree a, we must inspect the type
-- argument a, thus we incur some extra constraints if we want
-- polymorphism. It is preferrable to apply the type class
-- BaseCase to the instance head (Tree a) as follows, as
-- it doesn't reduce to something worth seeing.
--
--
-- {-# LANGUAGE FlexibleContexts, UndecidableInstances #-}
--
-- instance (Arbitrary a, BaseCase (Tree a))
-- => Arbitrary (Tree a) where
-- arbitrary = genericArbitrary' (1 % 2 % ())
--
--
-- The BaseCase type class finds values of minimal depth, where
-- the depth of a constructor is defined as 1 + max(0, depths of
-- fields), e.g., Leaf () has depth 2.
--
-- -- arbitrary = genericArbitraryRecG () -- `withBaseCase` baseGen ---- -- Some combinators are available for further tweaking: listOf', -- listOf1', vectorOf'. -- --
-- data User = User {
-- userName :: String,
-- userId :: Int,
-- userBalance :: Int
-- } deriving Generic
--
--
-- -- customGens :: FieldGen "userId" Int :+ Gen String :+ () -- customGens = -- (FieldGen . getNonNegative <$> arbitrary) :+ -- (listOf (elements (filter isAlphaNum [minBound .. maxBound]))) :+ -- () ---- -- Now we use the genericArbitraryG combinator and other -- G-suffixed variants that accept those explicit generators. -- --
-- instance Arbitrary User where -- arbitrary = genericArbitrarySingleG customGens ---- -- The custom generator modifiers that can occur in the list are: -- -- -- -- Suggestions to add more modifiers or otherwise improve this tutorial -- are welcome! The issue tracker is this way. module Generic.Random.Tutorial