-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Generic random generators -- -- Please see the README. @package generic-random @version 1.0.0.0 module Generic.Random.Internal.Generic -- | 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. genericArbitrary :: (Generic a, GA Unsized (Rep a)) => Weights a -> Gen a -- | Pick every constructor with equal probability. Equivalent to -- genericArbitrary uniform. -- --
--   genericArbitraryU :: Gen a
--   
genericArbitraryU :: (Generic a, GA Unsized (Rep a), UniformWeight_ (Rep a)) => Gen a -- | arbitrary for types with one constructor. Equivalent to -- genericArbitraryU, with a stricter type. -- --
--   genericArbitrarySingle :: Gen a
--   
genericArbitrarySingle :: (Generic a, GA Unsized (Rep 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 :: forall a. (Generic a, GA Sized (Rep a)) => Weights a -> Gen a data (:|) a b N :: a -> Int -> b -> (:|) a b data L (c :: Symbol) L :: L -- | 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 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. -- | Deprecated: Can be omitted 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 Prec a r 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 data Sized data Unsized -- | Generic Arbitrary class GA sized f ga :: GA sized f => proxy sized -> Weights_ f -> Int -> Gen (f p) gaSum' :: GASum sized f => proxy sized -> Weights_ f -> Int -> Gen (f p) class GASum sized f gaSum :: GASum sized f => proxy sized -> Int -> Weights_ f -> Gen (f p) class GAProduct sized f gaProduct :: GAProduct sized f => proxy sized -> Gen (f p) class GAProduct' f gaProduct' :: GAProduct' f => Gen (f p) 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 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 () 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.UniformWeight (Generic.Random.Internal.Generic.Weights_ f) => Generic.Random.Internal.Generic.UniformWeight_ f instance Generic.Random.Internal.Generic.GA sized f => Generic.Random.Internal.Generic.GA sized (GHC.Generics.M1 GHC.Generics.D c f) instance (Generic.Random.Internal.Generic.GASum sized f, Generic.Random.Internal.Generic.GASum sized g) => Generic.Random.Internal.Generic.GA sized (f GHC.Generics.:+: g) instance Generic.Random.Internal.Generic.GAProduct sized f => Generic.Random.Internal.Generic.GA sized (GHC.Generics.M1 GHC.Generics.C c f) instance (TypeError ...) => Generic.Random.Internal.Generic.GA sized f instance (Generic.Random.Internal.Generic.GASum sized f, Generic.Random.Internal.Generic.GASum sized g) => Generic.Random.Internal.Generic.GASum sized (f GHC.Generics.:+: g) instance Generic.Random.Internal.Generic.GAProduct sized f => Generic.Random.Internal.Generic.GASum sized (GHC.Generics.M1 i c f) instance Generic.Random.Internal.Generic.GAProduct' f => Generic.Random.Internal.Generic.GAProduct Generic.Random.Internal.Generic.Unsized f instance (Generic.Random.Internal.Generic.GAProduct' f, GHC.TypeLits.KnownNat (Generic.Random.Internal.Generic.Arity f)) => Generic.Random.Internal.Generic.GAProduct Generic.Random.Internal.Generic.Sized f instance Generic.Random.Internal.Generic.GAProduct Generic.Random.Internal.Generic.Sized GHC.Generics.U1 instance Generic.Random.Internal.Generic.GAProduct' GHC.Generics.U1 instance Test.QuickCheck.Arbitrary.Arbitrary c => Generic.Random.Internal.Generic.GAProduct' (GHC.Generics.K1 i c) instance (Generic.Random.Internal.Generic.GAProduct' f, Generic.Random.Internal.Generic.GAProduct' g) => Generic.Random.Internal.Generic.GAProduct' (f GHC.Generics.:*: g) instance Generic.Random.Internal.Generic.GAProduct' f => Generic.Random.Internal.Generic.GAProduct' (GHC.Generics.M1 i c f) instance GHC.Base.Applicative Generic.Random.Internal.Generic.Weighted instance GHC.Base.Alternative Generic.Random.Internal.Generic.Weighted 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' :: (Generic a, GA Sized (Rep a), BaseCase a) => Weights a -> Gen a -- | Equivalent to genericArbitrary' uniform. -- --
--   genericArbitraryU :: Gen a
--   
genericArbitraryU' :: (Generic a, GA Sized (Rep a), BaseCase a, UniformWeight_ (Rep 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 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 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.TypeLits.+ 1) => Generic.Random.Internal.BaseCase.BaseCaseSearching_ a z 'GHC.Base.Nothing 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 Generic.Random.Internal.BaseCase.BaseCaseSearching a 0 => Generic.Random.Internal.BaseCase.BaseCase a instance Generic.Random.Internal.BaseCase.GBCS f z y e => Generic.Random.Internal.BaseCase.GBCS (GHC.Generics.M1 i c f) z y e instance (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 k k1 (f :: GHC.Types.* -> *) (g :: GHC.Types.* -> *) (z :: k1) (e :: k). Generic.Random.Internal.BaseCase.GBCSSum f g z e 'GHC.Base.Nothing 'GHC.Base.Nothing instance forall k k1 (f :: GHC.Types.* -> *) (g :: GHC.Types.* -> *) (z :: k1) (e :: k) (m :: GHC.Types.Nat). Generic.Random.Internal.BaseCase.GBCSSum f g z e ('GHC.Base.Just m) 'GHC.Base.Nothing instance forall k k1 (f :: GHC.Types.* -> *) (g :: GHC.Types.* -> *) (z :: k1) (e :: k) (n :: GHC.Types.Nat). Generic.Random.Internal.BaseCase.GBCSSum f g z e 'GHC.Base.Nothing ('GHC.Base.Just n) instance forall k k1 (f :: GHC.Types.* -> *) (g :: GHC.Types.* -> *) (z :: k1) (e :: k) (m :: GHC.Types.Nat) (n :: GHC.Types.Nat). Generic.Random.Internal.BaseCase.GBCSSumCompare f g z e (GHC.TypeLits.CmpNat m n) => Generic.Random.Internal.BaseCase.GBCSSum f g z e ('GHC.Base.Just m) ('GHC.Base.Just n) instance forall k k1 (f :: GHC.Types.* -> *) (g :: GHC.Types.* -> *) (z :: k1) (e :: k). Generic.Random.Internal.BaseCase.GBCSSumCompare f g z e 'GHC.Types.EQ instance forall k k1 (f :: GHC.Types.* -> *) (g :: GHC.Types.* -> *) (z :: k1) (e :: k). Generic.Random.Internal.BaseCase.GBCSSumCompare f g z e 'GHC.Types.LT instance forall k k1 (f :: GHC.Types.* -> *) (g :: GHC.Types.* -> *) (z :: k1) (e :: k). Generic.Random.Internal.BaseCase.GBCSSumCompare f g z e 'GHC.Types.GT instance (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 k k1 (yf :: GHC.Base.Maybe GHC.Types.Nat) (yg :: GHC.Base.Maybe GHC.Types.Nat) (f :: GHC.Types.* -> *) (g :: GHC.Types.* -> *) (z :: k1) (e :: k). (yf Generic.Random.Internal.BaseCase.&&? yg) ~ 'GHC.Base.Nothing => Generic.Random.Internal.BaseCase.GBCSProduct f g z e yf yg instance forall k k1 (f :: GHC.Types.* -> *) (g :: GHC.Types.* -> *) (z :: k1) (e :: k) (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 t (t1 :: t). Generic.Random.Internal.BaseCase.IsMaybe ('GHC.Base.Just t1) instance Generic.Random.Internal.BaseCase.IsMaybe 'GHC.Base.Nothing instance (Generic.Random.Internal.BaseCase.BaseCaseSearch c (z GHC.TypeLits.- 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 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 -> GHC.Types.*) 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 (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 -- | Simple GHC.Generics-based arbitrary generators. -- -- For more information: -- -- module Generic.Random -- | 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. genericArbitrary :: (Generic a, GA Unsized (Rep a)) => Weights a -> Gen a -- | Pick every constructor with equal probability. Equivalent to -- genericArbitrary uniform. -- --
--   genericArbitraryU :: Gen a
--   
genericArbitraryU :: (Generic a, GA Unsized (Rep a), UniformWeight_ (Rep a)) => Gen a -- | arbitrary for types with one constructor. Equivalent to -- genericArbitraryU, with a stricter type. -- --
--   genericArbitrarySingle :: Gen a
--   
genericArbitrarySingle :: (Generic a, GA Unsized (Rep a), Weights_ (Rep a) ~ L c0) => 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' :: (Generic a, GA Sized (Rep a), BaseCase a) => Weights a -> Gen a -- | Equivalent to genericArbitrary' uniform. -- --
--   genericArbitraryU :: Gen a
--   
genericArbitraryU' :: (Generic a, GA Sized (Rep a), BaseCase a, UniformWeight_ (Rep a)) => Gen a -- | Decrease size at every recursive call, but don't do anything different -- at size 0. -- --
--   genericArbitraryRec (7 % 11 % 13 % ()) :: Gen a
--   
genericArbitraryRec :: forall a. (Generic a, GA Sized (Rep a)) => Weights 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 -- | Uniform distribution. uniform :: UniformWeight_ (Rep a) => Weights 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 -- | Custom instances can override the default behavior. class BaseCase a -- | Generator of base cases. baseCase :: BaseCase a => Gen a -- | A smart constructor to specify a custom distribution. -- | Deprecated: Can be omitted weights :: (Weights_ (Rep a), Int, ()) -> Weights a -- | Reexport of Generic.Random, for backwards-compatibility. module Generic.Random.Generic -- | Generic implementations of QuickCheck's arbitrary. -- --

Example

-- -- Define your type. -- --
--   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)
--       ]
--   
-- --

Distribution of constructors

-- -- The distribution of constructors can be specified as a special list of -- weights in the same order as the data type definition. This -- assigns to each constructor a probability proportional to its weight; -- in other words, p_C = weight_C / sumOfWeights. -- -- The list of weights is built up with the (%) operator -- as a cons, and using the unit () as the empty list, in the -- order corresponding to the data type definition. The uniform -- distribution can be obtained with uniform. -- --

Uniform distribution

-- -- You can specify the uniform distribution (all weights equal) with -- uniform. (genericArbitraryU is available as a shorthand -- for genericArbitrary uniform.) -- -- Note that for many recursive types, a uniform distribution tends to -- produce big or even infinite values. -- --

Typed weights

-- -- GHC 8.0.1 and above only (base ≥ 4.9). -- -- The weights actually have type W "ConstructorName" -- (just a newtype around Int), so that you can annotate a weight -- with its corresponding constructor, and it will be checked that you -- got the order right. -- -- This will type-check. -- --
--   ((x :: W "Leaf") % (y :: W "Node") % ()) :: Weights (Tree a)
--   (x % (y :: W "Node") % ()) :: Weights (Tree a)
--   
-- -- This will not: the first requires an order of constructors different -- from the definition of the Tree type; the second doesn't have -- the right number of weights. -- --
--   ((x :: W "Node") % y % ()) :: Weights (Tree a)
--   (x % y % z % ()) :: Weights (Tree a)
--   
-- --

Ensuring termination

-- -- As mentioned earlier, one must be careful with recursive types to -- avoid producing extremely large values. -- -- The alternative generator genericArbitrary' implements a simple -- strategy to keep values at reasonable sizes: the size parameter of -- Gen is divided among the fields of the chosen constructor. -- When it reaches zero, the generator selects a small term of the given -- type. This generally ensures that the number of constructors remains -- close to the initial size parameter passed to Gen. -- --
--   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
--   
module Generic.Random.Tutorial