@@ -23,7 +23,6 @@ module Test.QuickCheck.StateModel (
2323 EnvEntry (.. ),
2424 pattern (:=?) ,
2525 Env ,
26- Realized ,
2726 Generic ,
2827 IsPerformResult ,
2928 monitorPost ,
@@ -41,12 +40,9 @@ module Test.QuickCheck.StateModel (
4140) where
4241
4342import Control.Monad
44- import Control.Monad.Identity
4543import Control.Monad.Reader
46- import Control.Monad.State
4744import Control.Monad.Writer (WriterT , runWriterT , tell )
4845import Data.Data
49- import Data.Kind
5046import Data.List
5147import Data.Monoid (Endo (.. ))
5248import Data.Set qualified as Set
@@ -178,15 +174,6 @@ instance {-# OVERLAPPING #-} IsPerformResult Void a where
178174instance {-# OVERLAPPABLE #-} (PerformResult e a ~ Either e a ) => IsPerformResult e a where
179175 performResultToEither = id
180176
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-
190177newtype PostconditionM m a = PostconditionM { runPost :: WriterT (Endo Property , Endo Property ) m a }
191178 deriving (Functor , Applicative , Monad )
192179
@@ -221,57 +208,57 @@ class (forall a. Show (Action state a), Monad m) => RunModel state m where
221208 --
222209 -- The `Lookup` parameter provides an /environment/ to lookup `Var
223210 -- 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 )
225212
226213 -- | Postcondition on the `a` value produced at some step.
227214 -- The result is `assert`ed and will make the property fail should it be `False`. This is useful
228215 -- 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
230217 postcondition _ _ _ _ = pure True
231218
232219 -- | Postcondition on the result of running a _negative_ `Action`.
233220 -- The result is `assert`ed and will make the property fail should it be `False`. This is useful
234221 -- to check the implementation produces e.g. the expected errors or to check that the SUT hasn't
235222 -- 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
237224 postconditionOnFailure _ _ _ _ = pure True
238225
239226 -- | Allows the user to attach additional information to the `Property` at each step of the process.
240227 -- This function is given the full transition that's been executed, including the start and ending
241228 -- `state`, the `Action`, the current environment to `Lookup` and the value produced by `perform`
242229 -- 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
244231 monitoring _ _ _ _ prop = prop
245232
246233 -- | 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
248235 monitoringFailure _ _ _ _ prop = prop
249236
250- type LookUp m = forall a . Typeable a = > Var a -> Realized m a
237+ type LookUp = forall a . Typeable a = > Var a -> a
251238
252- type Env m = [EnvEntry m ]
239+ type Env = [EnvEntry ]
253240
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
256243
257244infix 5 :==
258245
259- pattern (:=?) :: forall a m . Typeable a => Var a -> Realized m a -> EnvEntry m
246+ pattern (:=?) :: forall a . Typeable a => Var a -> a -> EnvEntry
260247pattern v :=? val <- (viewAtType -> Just (v, val))
261248
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 )
263250viewAtType ((v :: Var b ) :== val)
264251 | Just Refl <- eqT @ a @ b = Just (v, val)
265252 | otherwise = Nothing
266253
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
268255lookUpVarMaybe [] _ = Nothing
269256lookUpVarMaybe (((v' :: Var b ) :== a) : env) v =
270257 case eqT @ a @ b of
271258 Just Refl | v == v' -> Just a
272259 _ -> lookUpVarMaybe env v
273260
274- lookUpVar :: Typeable a => Env m -> Var a -> Realized m a
261+ lookUpVar :: Typeable a => Env -> Var a -> a
275262lookUpVar env v = case lookUpVarMaybe env v of
276263 Nothing -> error $ " Variable " ++ show v ++ " is not bound at type " ++ show (typeRep v) ++ " !"
277264 Just a -> a
@@ -505,7 +492,7 @@ runActions
505492 , forall a . IsPerformResult e a
506493 )
507494 => Actions state
508- -> PropertyM m (Annotated state , Env m )
495+ -> PropertyM m (Annotated state , Env )
509496runActions (Actions_ rejected (Smart _ actions)) = do
510497 (finalState, env) <- runSteps initialAnnotatedState [] actions
511498 unless (null rejected) $
@@ -523,9 +510,9 @@ runSteps
523510 , forall a . IsPerformResult e a
524511 )
525512 => Annotated state
526- -> Env m
513+ -> Env
527514 -> [Step state ]
528- -> PropertyM m (Annotated state , Env m )
515+ -> PropertyM m (Annotated state , Env )
529516runSteps s env [] = return (s, reverse env)
530517runSteps s env ((v := act) : as) = do
531518 pre $ computePrecondition s act
0 commit comments