-- 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 --genericArbitraryRec :: (GArbitrary SizedOpts 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. data Options (s :: Sizing) (g :: [Type]) Options :: GenList g -> Options [_generators] :: Options -> GenList g unsizedOpts :: UnsizedOpts sizedOpts :: SizedOpts -- | Whether to decrease the size parameter before generating fields. data Sizing Sized :: Sizing Unsized :: Sizing type UnsizedOpts = (Options 'Unsized '[] :: Type) type SizedOpts = (Options 'Sized '[] :: Type) proxySizing :: opts -> Proxy (SizingOf opts) setSized :: Options s g -> Options 'Sized g setUnsized :: Options s g -> Options 'Unsized g -- | Heterogeneous list of generators. data GenList (g :: [Type]) [Nil] :: GenList '[] [:@] :: Gen a -> GenList g -> GenList (a : g) class HasGenerators opts generators :: HasGenerators opts => opts -> GenList (GeneratorsOf opts) setGenerators :: GenList g -> Options s g0 -> Options s g -- | A marker for a generator which overrides a specific field named -- s. -- -- Available only for base >= 4.9. newtype Field (s :: Symbol) a Field :: a -> Field a [unField] :: Field a -> a -- | Field constructor with the field name given via a proxy. field :: proxy s -> a -> Field s a -- | 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 (g :: [Type]) (sel :: Maybe Symbol) a arbitraryOr :: ArbitraryOr g sel a => proxy sel -> GenList g -> 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 (Generic.Random.Internal.Generic.GeneratorsOf opts) (Generic.Random.Internal.Generic.SelectorName d) c) => Generic.Random.Internal.Generic.GAProduct' opts (GHC.Generics.S1 d (GHC.Generics.K1 i c)) instance Generic.Random.Internal.Generic.ArbitraryOr (a : g) sel a instance Generic.Random.Internal.Generic.ArbitraryOr g sel a => Generic.Random.Internal.Generic.ArbitraryOr (b : g) sel a instance Test.QuickCheck.Arbitrary.Arbitrary a => Generic.Random.Internal.Generic.ArbitraryOr '[] sel a instance Generic.Random.Internal.Generic.ArbitraryOr (Generic.Random.Internal.Generic.Field n a : g) ('GHC.Base.Just n) a instance (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 Generic.Random.Internal.Generic.GAProduct' opts f => Generic.Random.Internal.Generic.GAProduct 'Generic.Random.Internal.Generic.Unsized opts f instance Generic.Random.Internal.Generic.GAProduct' opts GHC.Generics.U1 instance (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 --genericArbitrary' :: (GArbitrary SizedOpts a, BaseCase a) => Weights a -> Gen a -- | Equivalent to genericArbitrary' uniform. -- --
-- genericArbitraryU :: Gen a --genericArbitraryU' :: (GArbitrary SizedOpts 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 --genericArbitraryRec :: (GArbitrary SizedOpts 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 --genericArbitrary' :: (GArbitrary SizedOpts a, BaseCase a) => Weights a -> Gen a -- | Equivalent to genericArbitrary' uniform. -- --
-- genericArbitraryU :: Gen a --genericArbitraryU' :: (GArbitrary SizedOpts 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) (g :: [Type]) type SizedOpts = (Options 'Sized '[] :: Type) sizedOpts :: SizedOpts type UnsizedOpts = (Options 'Unsized '[] :: Type) 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 GenList (g :: [Type]) [Nil] :: GenList '[] [:@] :: Gen a -> GenList g -> GenList (a : g) -- | A marker for a generator which overrides a specific field named -- s. -- -- Available only for base >= 4.9. newtype Field (s :: Symbol) a Field :: a -> Field a [unField] :: Field a -> a -- | Field constructor with the field name given via a proxy. field :: proxy s -> a -> Field s a setGenerators :: GenList g -> Options s g0 -> Options s g -- | 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 -- | Reexport of Generic.Random, for backwards-compatibility. -- | Deprecated: Use Generic.Random instead module Generic.Random.Generic -- | 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 (8 % 9 % ()) ---- -- 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. ---- --
-- genericArbitrary' (x1 % ... % xn % ()) ---- -- Here is an example with nullary constructors: -- --
-- data Bush = Leaf1 | Leaf2 | Node3 Bush Bush Bush -- deriving Generic -- -- instance Arbitrary Bush where -- arbitrary = genericArbitrary' (1 % 2 % 3 % ()) ---- -- Here, genericArbitrary' is equivalent to: -- --
-- genericArbitrary' :: Weights Bush -> Gen Bush -- genericArbitrary' (x % y % z % ()) = -- sized $ \n -> -- if n == 0 then -- -- If the size parameter is zero, only nullary alternatives are kept. -- elements [Leaf1, Leaf2] -- else -- frequency -- [ (x, return Leaf1) -- , (y, return Leaf2) -- , (z, resize (n `div` 3) node) -- 3 because Node3 is 3-ary -- ] -- where -- node = Node3 <$> arbitrary <*> arbitrary <*> arbitrary ---- -- If we want to generate a value of type Tree (), there is a -- value of depth 1 that we can use to end recursion: Leaf (). -- --
-- genericArbitrary' :: Weights (Tree ()) -> Gen (Tree ()) -- genericArbitrary' (x % y % ()) = -- sized $ \n -> -- if n == 0 then -- return (Leaf ()) -- else -- frequency -- [ (x, Leaf <$> arbitrary) -- , (y, resize (n `div` 2) $ Node <$> arbitrary <*> arbitrary) -- ] ---- -- Because the argument of Tree must be inspected in order to -- discover values of type Tree (), we incur some extra -- constraints if we want polymorphism. -- --
-- {-# LANGUAGE FlexibleContexts, UndecidableInstances #-}
--
-- instance (Arbitrary a, BaseCase (Tree a))
-- => Arbitrary (Tree a) where
-- arbitrary = genericArbitrary' (1 % 2 % ())
--
--
-- By default, the BaseCase type class looks for all values of
-- minimal depth (constructors have depth 1 + max(0, depths of
-- fields)).
--
-- This can easily be overriden by declaring a specialized
-- BaseCase instance, such as this one:
--
-- -- instance Arbitrary a => BaseCase (Tree a) where -- baseCase = oneof [leaf, simpleNode] -- where -- leaf = Leaf <$> arbitrary -- simpleNode = Node <$> leaf <*> leaf ---- -- An alternative base case can also be specified directly in the -- arbitrary definition with the withBaseCase combinator. -- -- genericArbitraryRec is a variant of genericArbitrary' -- with no base case. -- --
-- instance Arbitrary Bush where -- arbitrary = -- genericArbitraryRec (1 % 2 % 3 % ()) -- `withBaseCase` return Leaf1 ---- --
-- data User = User {
-- userName :: String,
-- userId :: Int,
-- userBalance :: Int
-- } deriving Generic
--
--
-- -- customGens :: GenList '[Field "userId" Int, String] -- customGens = -- (Field . getNonNegative <$> arbitrary) :@ -- (listOf (elements (filter isAlphaNum [minBound .. maxBound]))) :@ -- Nil ---- -- And to use the genericArbitraryG and variants that accept those -- explicit generators. -- --
-- instance Arbitrary User where -- arbitrary = genericArbitrarySingleG customGens --module Generic.Random.Tutorial