@@ -16,19 +16,21 @@ module Test.QuickCheck.StateModel.Lockstep.API (
1616 , ModelLookUp
1717 , ModelVar
1818 , ModelShrinkVar
19+ , RealLookUp
1920 -- * Variable context
2021 , ModelVarContext
2122 , findVars
2223 , lookupVar
2324 , shrinkVar
25+ , realLookupVar
2426 ) where
2527
2628import Data.Constraint (Dict (.. ))
2729import Data.Kind
2830import Data.Typeable
2931
3032import Test.QuickCheck (Gen )
31- import Test.QuickCheck.StateModel (StateModel , Any , RunModel , Realized , Action )
33+ import Test.QuickCheck.StateModel (StateModel , Any , RunModel , Realized , Action , LookUp )
3234
3335import Test.QuickCheck.StateModel.Lockstep.EnvF (EnvF )
3436import Test.QuickCheck.StateModel.Lockstep.GVar (GVar , AnyGVar (.. ), fromVar )
@@ -181,21 +183,19 @@ class ( InLockstep state
181183-- | An action in the lock-step model
182184type LockstepAction state = Action (Lockstep state )
183185
184- -- | Look up a variable for model execution
185- --
186- -- The type of the variable is the type in the /real/ system.
186+ -- | See 'lookupVar'.
187187type ModelLookUp state = forall a . ModelVar state a -> ModelValue state a
188188
189- -- | Find variables of the appropriate type
190- --
191- -- The type you pass must be the result type of (previously executed) actions.
192- -- If you want to change the type of the variable, see 'EnvF.mapGVar'.
189+ -- | See 'findVars'.
193190type ModelFindVariables state = forall a .
194191 Typeable a
195192 = > Proxy a -> [GVar (ModelOp state ) a ]
196193
197- -- | Shrink variables to /earlier/ variables of the same type.
198- type ModelShrinkVar state a = ModelVar state a -> [ModelVar state a ]
194+ -- | See 'shrinkVar'.
195+ type ModelShrinkVar state = forall a . ModelVar state a -> [ModelVar state a ]
196+
197+ -- | See 'realLookupVar'.
198+ type RealLookUp m op = forall a . Proxy m -> LookUp m -> GVar op a -> Realized m a
199199
200200-- | Variables with a "functor-esque" instance
201201type ModelVar state = GVar (ModelOp state )
@@ -207,24 +207,45 @@ type ModelVar state = GVar (ModelOp state)
207207-- | The environment of known variables and their (model) values.
208208--
209209-- This environment can be queried for information about known variables through
210- -- 'findVars' and 'lookupVar '. This environment is updated automically by the
211- -- lockstep framework.
210+ -- 'findVars', 'lookupVar', and 'shrinkVar '. This environment is updated
211+ -- automically by the lockstep framework.
212212type ModelVarContext state = EnvF (ModelValue state )
213213
214- -- | See 'ModelFindVariables'.
214+ -- | Find variables of the appropriate type
215+ --
216+ -- The type you pass must be the result type of (previously executed) actions.
217+ -- If you want to change the type of the variable, see 'EnvF.mapGVar'.
215218findVars ::
216219 InLockstep state
217220 => ModelVarContext state -> ModelFindVariables state
218221findVars env _ = map fromVar $ EnvF. keysOfType env
219222
220- -- | See 'ModelLookUp'.
223+ -- | Look up a variable for execution of the model.
224+ --
225+ -- The type of the variable is the type in the /real/ system.
221226lookupVar ::
222227 InLockstep state
223228 => ModelVarContext state -> ModelLookUp state
224- lookupVar env = EnvF. lookUpEnvF env
229+ lookupVar env gvar = case EnvF. lookUpEnvF env gvar of
230+ Just x -> x
231+ Nothing -> error
232+ " lookupVar: the variable (ModelVar) must be well-defined and evaluable, \
233+ \but this requirement was violated. Normally, this is guaranteed by the \
234+ \default test 'precondition'."
225235
226- -- | See 'ModelShrinkVar' .
236+ -- | Shrink variables to /earlier/ variables of the same type .
227237shrinkVar ::
228238 (Typeable state , InterpretOp (ModelOp state ) (ModelValue state ))
229- => ModelVarContext state -> ModelShrinkVar state a
230- shrinkVar env var = EnvF. shrinkGVar env var
239+ => ModelVarContext state -> ModelShrinkVar state
240+ shrinkVar env var = EnvF. shrinkGVar env var
241+
242+ -- | Look up a variable for execution of the real system.
243+ --
244+ -- The type of the variable is the type in the /real/ system.
245+ realLookupVar :: InterpretOp op (WrapRealized m ) => RealLookUp m op
246+ realLookupVar p lookUp gvar = case EnvF. lookUpGVar p lookUp gvar of
247+ Just x -> x
248+ Nothing -> error
249+ " realLookupVar: the variable (GVar) must be well-defined and evaluable, \
250+ \but this requirement was violated. Normally, this is guaranteed by the \
251+ \default test 'precondition'."
0 commit comments