@@ -23,7 +23,6 @@ module Test.QuickCheck.StateModel (
23
23
EnvEntry (.. ),
24
24
pattern (:=?) ,
25
25
Env ,
26
- Realized ,
27
26
Generic ,
28
27
IsPerformResult ,
29
28
monitorPost ,
@@ -41,12 +40,9 @@ module Test.QuickCheck.StateModel (
41
40
) where
42
41
43
42
import Control.Monad
44
- import Control.Monad.Identity
45
43
import Control.Monad.Reader
46
- import Control.Monad.State
47
44
import Control.Monad.Writer (WriterT , runWriterT , tell )
48
45
import Data.Data
49
- import Data.Kind
50
46
import Data.List
51
47
import Data.Monoid (Endo (.. ))
52
48
import Data.Set qualified as Set
@@ -178,15 +174,6 @@ instance {-# OVERLAPPING #-} IsPerformResult Void a where
178
174
instance {-# OVERLAPPABLE #-} (PerformResult e a ~ Either e a ) => IsPerformResult e a where
179
175
performResultToEither = id
180
176
181
- -- TODO: maybe it makes sense to write
182
- -- out a long list of these instances
183
- type family Realized (m :: Type -> Type ) a :: Type
184
- type instance Realized IO a = a
185
- type instance Realized (StateT s m ) a = Realized m a
186
- type instance Realized (ReaderT r m ) a = Realized m a
187
- type instance Realized (WriterT w m ) a = Realized m a
188
- type instance Realized Identity a = a
189
-
190
177
newtype PostconditionM m a = PostconditionM { runPost :: WriterT (Endo Property , Endo Property ) m a }
191
178
deriving (Functor , Applicative , Monad )
192
179
@@ -221,57 +208,57 @@ class (forall a. Show (Action state a), Monad m) => RunModel state m where
221
208
--
222
209
-- The `Lookup` parameter provides an /environment/ to lookup `Var
223
210
-- a` instances from previous steps.
224
- perform :: Typeable a => state -> Action state a -> LookUp m -> m (PerformResult (Error state ) ( Realized m a ) )
211
+ perform :: Typeable a => state -> Action state a -> LookUp -> m (PerformResult (Error state ) a )
225
212
226
213
-- | Postcondition on the `a` value produced at some step.
227
214
-- The result is `assert`ed and will make the property fail should it be `False`. This is useful
228
215
-- to check the implementation produces expected values.
229
- postcondition :: (state , state ) -> Action state a -> LookUp m -> Realized m a -> PostconditionM m Bool
216
+ postcondition :: (state , state ) -> Action state a -> LookUp -> a -> PostconditionM m Bool
230
217
postcondition _ _ _ _ = pure True
231
218
232
219
-- | Postcondition on the result of running a _negative_ `Action`.
233
220
-- The result is `assert`ed and will make the property fail should it be `False`. This is useful
234
221
-- to check the implementation produces e.g. the expected errors or to check that the SUT hasn't
235
222
-- been updated during the execution of the negative action.
236
- postconditionOnFailure :: (state , state ) -> Action state a -> LookUp m -> Either (Error state ) ( Realized m a ) -> PostconditionM m Bool
223
+ postconditionOnFailure :: (state , state ) -> Action state a -> LookUp -> Either (Error state ) a -> PostconditionM m Bool
237
224
postconditionOnFailure _ _ _ _ = pure True
238
225
239
226
-- | Allows the user to attach additional information to the `Property` at each step of the process.
240
227
-- This function is given the full transition that's been executed, including the start and ending
241
228
-- `state`, the `Action`, the current environment to `Lookup` and the value produced by `perform`
242
229
-- while executing this step.
243
- monitoring :: (state , state ) -> Action state a -> LookUp m -> Either (Error state ) ( Realized m a ) -> Property -> Property
230
+ monitoring :: (state , state ) -> Action state a -> LookUp -> Either (Error state ) a -> Property -> Property
244
231
monitoring _ _ _ _ prop = prop
245
232
246
233
-- | Allows the user to attach additional information to the `Property` if a positive action fails.
247
- monitoringFailure :: state -> Action state a -> LookUp m -> Error state -> Property -> Property
234
+ monitoringFailure :: state -> Action state a -> LookUp -> Error state -> Property -> Property
248
235
monitoringFailure _ _ _ _ prop = prop
249
236
250
- type LookUp m = forall a . Typeable a = > Var a -> Realized m a
237
+ type LookUp = forall a . Typeable a = > Var a -> a
251
238
252
- type Env m = [EnvEntry m ]
239
+ type Env = [EnvEntry ]
253
240
254
- data EnvEntry m where
255
- (:==) :: Typeable a => Var a -> Realized m a -> EnvEntry m
241
+ data EnvEntry where
242
+ (:==) :: Typeable a => Var a -> a -> EnvEntry
256
243
257
244
infix 5 :==
258
245
259
- pattern (:=?) :: forall a m . Typeable a => Var a -> Realized m a -> EnvEntry m
246
+ pattern (:=?) :: forall a . Typeable a => Var a -> a -> EnvEntry
260
247
pattern v :=? val <- (viewAtType -> Just (v, val))
261
248
262
- viewAtType :: forall a m . Typeable a => EnvEntry m -> Maybe (Var a , Realized m a )
249
+ viewAtType :: forall a . Typeable a => EnvEntry -> Maybe (Var a , a )
263
250
viewAtType ((v :: Var b ) :== val)
264
251
| Just Refl <- eqT @ a @ b = Just (v, val)
265
252
| otherwise = Nothing
266
253
267
- lookUpVarMaybe :: forall a m . Typeable a => Env m -> Var a -> Maybe ( Realized m a )
254
+ lookUpVarMaybe :: forall a . Typeable a => Env -> Var a -> Maybe a
268
255
lookUpVarMaybe [] _ = Nothing
269
256
lookUpVarMaybe (((v' :: Var b ) :== a) : env) v =
270
257
case eqT @ a @ b of
271
258
Just Refl | v == v' -> Just a
272
259
_ -> lookUpVarMaybe env v
273
260
274
- lookUpVar :: Typeable a => Env m -> Var a -> Realized m a
261
+ lookUpVar :: Typeable a => Env -> Var a -> a
275
262
lookUpVar env v = case lookUpVarMaybe env v of
276
263
Nothing -> error $ " Variable " ++ show v ++ " is not bound at type " ++ show (typeRep v) ++ " !"
277
264
Just a -> a
@@ -505,7 +492,7 @@ runActions
505
492
, forall a . IsPerformResult e a
506
493
)
507
494
=> Actions state
508
- -> PropertyM m (Annotated state , Env m )
495
+ -> PropertyM m (Annotated state , Env )
509
496
runActions (Actions_ rejected (Smart _ actions)) = do
510
497
(finalState, env) <- runSteps initialAnnotatedState [] actions
511
498
unless (null rejected) $
@@ -523,9 +510,9 @@ runSteps
523
510
, forall a . IsPerformResult e a
524
511
)
525
512
=> Annotated state
526
- -> Env m
513
+ -> Env
527
514
-> [Step state ]
528
- -> PropertyM m (Annotated state , Env m )
515
+ -> PropertyM m (Annotated state , Env )
529
516
runSteps s env [] = return (s, reverse env)
530
517
runSteps s env ((v := act) : as) = do
531
518
pre $ computePrecondition s act
0 commit comments