git.iko.soy/typeable/generic-arbitrary
on master help sign in
remove TypeApplications
91d1019Aleksey Uymanov
generic-arbitrary.cabal−1
@@ -41,7 +41,6 @@ library
41 , PolyKinds
41 , PolyKinds
42 , RankNTypes
42 , RankNTypes
43 , ScopedTypeVariables
43 , ScopedTypeVariables
44− , TypeApplications
45 , TypeFamilies
44 , TypeFamilies
46 , TypeOperators
45 , TypeOperators
47 , TypeSynonymInstances
46 , TypeSynonymInstances
src/Test/QuickCheck/Arbitrary/Generic.hs+28−25
@@ -91,12 +91,12 @@ type family SumLen a :: Nat where
91-- * a: some part of the `Rep self`
91-- * a: some part of the `Rep self`
92-- * finite: Is `a` finite? Infinite type has no finite values (like Stream)
92-- * finite: Is `a` finite? Infinite type has no finite values (like Stream)
93class (Finite self a ~ finite) => GArbitrary self a (finite :: Bool) where
93class (Finite self a ~ finite) => GArbitrary self a (finite :: Bool) where
94− gArbitrary :: QC.Gen (a x)
94+ gArbitrary :: Proxy self -> QC.Gen (a x)
95
95
96instance
96instance
97 ( GArbitrary self (C1 c f) 'True
97 ( GArbitrary self (C1 c f) 'True
98 ) => GArbitrary self (D1 t (C1 c f)) 'True where
98 ) => GArbitrary self (D1 t (C1 c f)) 'True where
99− gArbitrary = M1 <$> gArbitrary @self
99+ gArbitrary _ = M1 <$> gArbitrary (Proxy :: Proxy self)
100
100
101-- | The constructor meta information
101-- | The constructor meta information
102instance
102instance
@@ -104,27 +104,27 @@ instance
104 , KnownNat (ArgumentsCount f)
104 , KnownNat (ArgumentsCount f)
105 , AllFieldsFinal self f ~ some
105 , AllFieldsFinal self f ~ some
106 ) => GArbitrary self (C1 c f) some where
106 ) => GArbitrary self (C1 c f) some where
107− gArbitrary = M1 <$> scale predNat (gArbitrary @self)
107+ gArbitrary _ = M1 <$> scale predNat (gArbitrary (Proxy :: Proxy self))
108 where
108 where
109− argumentsCount = fromIntegral $ natVal (Proxy @(ArgumentsCount f))
109+ argumentsCount = fromIntegral $ natVal (Proxy :: Proxy (ArgumentsCount f))
110 predNat n = max 0 $ if argumentsCount > 1
110 predNat n = max 0 $ if argumentsCount > 1
111 then n `div` argumentsCount
111 then n `div` argumentsCount
112 else pred n
112 else pred n
113
113
114-- | Unit type instance
114-- | Unit type instance
115instance GArbitrary self U1 'True where
115instance GArbitrary self U1 'True where
116− gArbitrary = pure U1
116+ gArbitrary _ = pure U1
117
117
118-- | Constructor field meta information
118-- | Constructor field meta information
119instance GArbitrary self f some => GArbitrary self (S1 t f) some where
119instance GArbitrary self f some => GArbitrary self (S1 t f) some where
120− gArbitrary = M1 <$> gArbitrary @self
120+ gArbitrary _ = M1 <$> gArbitrary (Proxy :: Proxy self)
121
121
122-- | Data of the constructor field
122-- | Data of the constructor field
123instance
123instance
124 ( Arbitrary t
124 ( Arbitrary t
125 , Finite self (Rec0 t) ~ some
125 , Finite self (Rec0 t) ~ some
126 ) => GArbitrary self (Rec0 t) some where
126 ) => GArbitrary self (Rec0 t) some where
127− gArbitrary = K1 <$> arbitrary
127+ gArbitrary _ = K1 <$> arbitrary
128
128
129-- | Product
129-- | Product
130instance
130instance
@@ -132,21 +132,24 @@ instance
132 , GArbitrary self b bf
132 , GArbitrary self b bf
133 , (af && bf) ~ some
133 , (af && bf) ~ some
134 ) => GArbitrary self (a :*: b) some where
134 ) => GArbitrary self (a :*: b) some where
135+ gArbitrary _ = liftA2 (:*:)
135− gArbitrary = liftA2 (:*:) (gArbitrary @self) (gArbitrary @self)
136+ (gArbitrary (Proxy :: Proxy self)) (gArbitrary (Proxy :: Proxy self))
136
137
137instance
138instance
138 ( TypeError (ShowType self :<>: Text " refers to itself in all constructors")
139 ( TypeError (ShowType self :<>: Text " refers to itself in all constructors")
139 , AllFieldsFinal self f ~ 'False
140 , AllFieldsFinal self f ~ 'False
140 ) => GArbitrary self (D1 t (C1 c f)) 'False where
141 ) => GArbitrary self (D1 t (C1 c f)) 'False where
141− gArbitrary = error "Unreachable"
142+ gArbitrary _ = error "Unreachable"
142
143
143-- | ADT declaration with multiple constructors
144-- | ADT declaration with multiple constructors
144instance
145instance
145 ( FiniteSum self a b af bf
146 ( FiniteSum self a b af bf
146 , GArbitrary self (a :+: b) 'True
147 , GArbitrary self (a :+: b) 'True
147 ) => GArbitrary self (D1 t (a :+: b)) 'True where
148 ) => GArbitrary self (D1 t (a :+: b)) 'True where
148− gArbitrary = sized $ \s -> M1 <$>
149+ gArbitrary _ = sized $ \s -> M1 <$>
150+ if s > 1
149− if s > 1 then gArbitrary @self else oneof (finiteSum @self @a @b)
151+ then gArbitrary (Proxy :: Proxy self)
152+ else oneof (finiteSum (Proxy :: Proxy self))
150
153
151-- | Any sum inside of declaration
154-- | Any sum inside of declaration
152instance
155instance
@@ -154,9 +157,9 @@ instance
154 , KnownNat (SumLen a), KnownNat (SumLen b)
157 , KnownNat (SumLen a), KnownNat (SumLen b)
155 , (af || bf) ~ some
158 , (af || bf) ~ some
156 ) => GArbitrary self (a :+: b) some where
159 ) => GArbitrary self (a :+: b) some where
157− gArbitrary = frequency
160+ gArbitrary _ = frequency
158− [ (lfreq, G.L1 <$> gArbitrary @self)
161+ [ (lfreq, G.L1 <$> gArbitrary (Proxy :: Proxy self))
159− , (rfreq, G.R1 <$> gArbitrary @self) ]
162+ , (rfreq, G.R1 <$> gArbitrary (Proxy :: Proxy self)) ]
160 where
163 where
161 lfreq = fromIntegral $ natVal (Proxy :: Proxy (SumLen a))
164 lfreq = fromIntegral $ natVal (Proxy :: Proxy (SumLen a))
162 rfreq = fromIntegral $ natVal (Proxy :: Proxy (SumLen b))
165 rfreq = fromIntegral $ natVal (Proxy :: Proxy (SumLen b))
@@ -164,52 +167,52 @@ instance
164class
167class
165 ( Finite self a ~ af, Finite self b ~ bf
168 ( Finite self a ~ af, Finite self b ~ bf
166 ) => FiniteSum self (a :: * -> *) (b :: * -> *) af bf where
169 ) => FiniteSum self (a :: * -> *) (b :: * -> *) af bf where
167− finiteSum :: [Gen ((a :+: b) p)]
170+ finiteSum :: Proxy self -> [Gen ((a :+: b) p)]
168
171
169instance
172instance
170 ( FiniteSumElem self a, FiniteSumElem self b
173 ( FiniteSumElem self a, FiniteSumElem self b
171 , Finite self a ~ 'True
174 , Finite self a ~ 'True
172 , Finite self b ~ 'True
175 , Finite self b ~ 'True
173 ) => FiniteSum self a b 'True 'True where
176 ) => FiniteSum self a b 'True 'True where
174− finiteSum = concat
177+ finiteSum _ = concat
175− [ fmap L1 <$> finiteElem @self @a
178+ [ fmap L1 <$> finiteElem (Proxy :: Proxy self)
176− , fmap R1 <$> finiteElem @self @b]
179+ , fmap R1 <$> finiteElem (Proxy :: Proxy self)]
177
180
178instance
181instance
179 ( FiniteSumElem self a
182 ( FiniteSumElem self a
180 , Finite self a ~ 'True
183 , Finite self a ~ 'True
181 , Finite self b ~ 'False
184 , Finite self b ~ 'False
182 ) => FiniteSum self a b 'True 'False where
185 ) => FiniteSum self a b 'True 'False where
183− finiteSum = fmap L1 <$> finiteElem @self @a
186+ finiteSum _ = fmap L1 <$> finiteElem (Proxy :: Proxy self)
184
187
185instance
188instance
186 ( FiniteSumElem self b
189 ( FiniteSumElem self b
187 , Finite self a ~ 'False
190 , Finite self a ~ 'False
188 , Finite self b ~ 'True
191 , Finite self b ~ 'True
189 ) => FiniteSum self a b 'False 'True where
192 ) => FiniteSum self a b 'False 'True where
190− finiteSum = fmap R1 <$> finiteElem @self @b
193+ finiteSum _ = fmap R1 <$> finiteElem (Proxy :: Proxy self)
191
194
192class FiniteSumElem self a where
195class FiniteSumElem self a where
193− finiteElem :: [Gen (a p)]
196+ finiteElem :: Proxy self -> [Gen (a p)]
194
197
195instance
198instance
196 ( FiniteSum self a b af bf
199 ( FiniteSum self a b af bf
197 ) => FiniteSumElem self (a :+: b) where
200 ) => FiniteSumElem self (a :+: b) where
198− finiteElem = finiteSum @self
201+ finiteElem _ = finiteSum (Proxy :: Proxy self)
199
202
200instance
203instance
201 ( GArbitrary self (C1 c f) 'True
204 ( GArbitrary self (C1 c f) 'True
202 ) => FiniteSumElem self (C1 c f) where
205 ) => FiniteSumElem self (C1 c f) where
203− finiteElem = [gArbitrary @self]
206+ finiteElem _ = [gArbitrary (Proxy :: Proxy self)]
204
207
205instance
208instance
206 ( TypeError (ShowType self :<>: Text " refers to itself in all constructors")
209 ( TypeError (ShowType self :<>: Text " refers to itself in all constructors")
207 , (Finite self a || Finite self b) ~ 'False
210 , (Finite self a || Finite self b) ~ 'False
208 ) => GArbitrary self (D1 t (a :+: b)) 'False where
211 ) => GArbitrary self (D1 t (a :+: b)) 'False where
209− gArbitrary = error "Unreachable"
212+ gArbitrary _ = error "Unreachable"
210
213
211genericArbitrary
214genericArbitrary
212 :: forall a ga some
215 :: forall a ga some
213 . (Generic a, GArbitrary a ga some, ga ~ Rep a)
216 . (Generic a, GArbitrary a ga some, ga ~ Rep a)
214 => Gen a
217 => Gen a
215−genericArbitrary = G.to <$> gArbitrary @a
218+genericArbitrary = G.to <$> gArbitrary (Proxy :: Proxy a)