@@ -53,7 +53,6 @@ module Test.QuickCheck.StateModel (
5353) where
5454
5555import Control.Monad
56- import Control.Monad.Reader
5756import Control.Monad.Writer
5857import Data.Data
5958import Data.Kind
@@ -165,27 +164,24 @@ class
165164
166165deriving instance (forall a . Show (Action state a )) => Show (Any (Action state ))
167166
168- newtype PostconditionM m a = PostconditionM { runPost :: WriterT (Endo Property , Endo Property ) m a }
167+ newtype PostconditionM a = PostconditionM { runPost :: Writer (Endo Property , Endo Property ) a }
169168 deriving (Functor , Applicative , Monad )
170169
171- instance MonadTrans PostconditionM where
172- lift = PostconditionM . lift
173-
174- evaluatePostCondition :: Monad m => PostconditionM m Bool -> PropertyM m ()
170+ evaluatePostCondition :: Monad m => PostconditionM Bool -> PropertyM m ()
175171evaluatePostCondition post = do
176- (b, (Endo mon, Endo onFail)) <- run . runWriterT . runPost $ post
172+ let (b, (Endo mon, Endo onFail)) = runWriter . runPost $ post
177173 monitor mon
178174 unless b $ monitor onFail
179175 assert b
180176
181177-- | Apply the property transformation to the property after evaluating
182178-- the postcondition. Useful for collecting statistics while avoiding
183179-- duplication between `monitoring` and `postcondition`.
184- monitorPost :: Monad m => (Property -> Property ) -> PostconditionM m ()
180+ monitorPost :: (Property -> Property ) -> PostconditionM ()
185181monitorPost m = PostconditionM $ tell (Endo m, mempty )
186182
187183-- | Acts as `Test.QuickCheck.counterexample` if the postcondition fails.
188- counterexamplePost :: Monad m => String -> PostconditionM m ()
184+ counterexamplePost :: String -> PostconditionM ()
189185counterexamplePost c = PostconditionM $ tell (mempty , Endo $ counterexample c)
190186
191187-- | The result required of `perform` depending on the `Error` type.
@@ -230,14 +226,14 @@ class (forall a. Show (Action state a), Show (Error state m), Monad m) => RunMod
230226 -- | Postcondition on the `a` value produced at some step.
231227 -- The result is `assert`ed and will make the property fail should it be `False`. This is useful
232228 -- to check the implementation produces expected values.
233- postcondition :: (state , state ) -> Action state a -> LookUp -> a -> PostconditionM m Bool
229+ postcondition :: (state , state ) -> Action state a -> LookUp -> a -> PostconditionM Bool
234230 postcondition _ _ _ _ = pure True
235231
236232 -- | Postcondition on the result of running a _negative_ `Action`.
237233 -- The result is `assert`ed and will make the property fail should it be `False`. This is useful
238234 -- to check the implementation produces e.g. the expected errors or to check that the SUT hasn't
239235 -- been updated during the execution of the negative action.
240- postconditionOnFailure :: (state , state ) -> Action state a -> LookUp -> Either (Error state m ) a -> PostconditionM m Bool
236+ postconditionOnFailure :: (state , state ) -> Action state a -> LookUp -> Either (Error state m ) a -> PostconditionM Bool
241237 postconditionOnFailure _ _ _ _ = pure True
242238
243239 -- | Allows the user to attach additional information to the `Property` at each step of the process.
@@ -624,7 +620,7 @@ runSteps s env ((v := act) : as) = do
624620 positiveActionSucceeded ret val = do
625621 (s', env', stateTransition) <- computeNewState ret
626622 evaluatePostCondition $
627- postcondition
623+ postcondition @ state @ m
628624 stateTransition
629625 action
630626 (lookUpVar env)
@@ -634,7 +630,7 @@ runSteps s env ((v := act) : as) = do
634630 negativeActionResult ret = do
635631 (s', env', stateTransition) <- computeNewState ret
636632 evaluatePostCondition $
637- postconditionOnFailure
633+ postconditionOnFailure @ state @ m
638634 stateTransition
639635 action
640636 (lookUpVar env)
0 commit comments