@@ -59,12 +59,6 @@ instance
5959 arbitrary = coerce (genericArbitrary :: Gen a)
6060 shrink = coerce (genericShrink :: a -> [a])
6161
62−
63−-- type family FinalConstructors self (a :: * -> *) :: [* -> *] where
64−-- FinalConstructors self (a :+: b) =
65−-- FinalConstructors self a :++: FinalConstructors self b
66−-- FinalConstructors self (M1 C t f) = If (AllFieldsFinal self f) '[M1 C t f] '[]
67−
6862type family AllFieldsFinal self (a :: * -> *) :: Bool where
6963 AllFieldsFinal self U1 = 'True
7064 AllFieldsFinal self (a :*: b) = AllFieldsFinal self a && AllFieldsFinal self b
@@ -147,7 +141,7 @@ instance
147141 , GArbitrary self (a :+: b) 'True
148142 ) => GArbitrary self (D1 t (a :+: b)) 'True where
149143 gArbitrary = sized $ \s -> M1 <$>
150− if s > 1 then gArbitrary @self else finiteSum @self
144+ if s > 1 then gArbitrary @self else oneof (finiteSum @self @a @b)
151145
152146-- | Any sum inside of declaration
153147instance
@@ -165,33 +159,33 @@ instance
165159class
166160 ( Finite self a ~ af, Finite self b ~ bf
167161 ) => FiniteSum self (a :: * -> *) (b :: * -> *) af bf where
168− finiteSum :: Gen ((a :+: b) p)
162+ finiteSum :: [Gen ((a :+: b) p)]
169163
170164instance
171165 ( FiniteSumElem self a, FiniteSumElem self b
172166 , Finite self a ~ 'True
173167 , Finite self b ~ 'True
174168 ) => FiniteSum self a b 'True 'True where
175− finiteSum = oneof
176− [ L1 <$> finiteElem @self
177− , R1 <$> finiteElem @self ]
169+ finiteSum = concat
170+ [ fmap L1 <$> finiteElem @self @a
171+ , fmap R1 <$> finiteElem @self @b]
178172
179173instance
180174 ( FiniteSumElem self a
181175 , Finite self a ~ 'True
182176 , Finite self b ~ 'False
183177 ) => FiniteSum self a b 'True 'False where
184− finiteSum = L1 <$> finiteElem @self
178+ finiteSum = fmap L1 <$> finiteElem @self @a
185179
186180instance
187181 ( FiniteSumElem self b
188182 , Finite self a ~ 'False
189183 , Finite self b ~ 'True
190184 ) => FiniteSum self a b 'False 'True where
191− finiteSum = R1 <$> finiteElem @self
185+ finiteSum = fmap R1 <$> finiteElem @self @b
192186
193187class FiniteSumElem self a where
194− finiteElem :: Gen (a p)
188+ finiteElem :: [Gen (a p)]
195189
196190instance
197191 ( FiniteSum self a b af bf
@@ -201,7 +195,7 @@ instance
201195instance
202196 ( GArbitrary self (C1 c f) 'True
203197 ) => FiniteSumElem self (C1 c f) where
204− finiteElem = gArbitrary @self
198+ finiteElem = [gArbitrary @self]
205199
206200instance
207201 ( TypeError (ShowType self :<>: Text " refers to itself in all constructors")