Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Make equality of Reference independent of the contents #203

Open
Lysxia opened this issue Feb 18, 2018 · 3 comments
Open

Make equality of Reference independent of the contents #203

Lysxia opened this issue Feb 18, 2018 · 3 comments

Comments

@Lysxia
Copy link
Collaborator

Lysxia commented Feb 18, 2018

We have an instance (Eq1 v, Eq a) => Eq (Reference v a) , which requires that the underlying reference type be comparable (Eq a). That happens to be fine with IORef but in general reference types such as mutable vectors do not have such an instance. A workaround is a wrapper that carries a unique identifier for each reference (see here for example), but could qc-state-machine integrate that somehow?

@stevana
Copy link
Collaborator

stevana commented Feb 20, 2018

Perhaps it would make sense to move your trick into the library? That way we can also use Map (Reference ...)-like models...

@stevana
Copy link
Collaborator

stevana commented May 18, 2018

I thought a bit more about this, and I'm beginning to wonder if post-conditions shouldn't have the type model Symbolic -> act Symbolic resp -> resp -> Bool?

Or perhaps the Var from Symbolic can be threaded through into Concrete and used for equality checks?

@stevana
Copy link
Collaborator

stevana commented Aug 20, 2018

I played around a bit more with this in #209, see:

data Concrete a where
  Concrete :: Typeable a => a -> Unique -> Concrete a

instance Eq (Concrete a) where
  Concrete _ u1 == Concrete _ u2 = u1 == u2

instance Eq (r a) => Eq (Reference a r) where
  Reference r1 == Reference r2 = r1 == r2

reference :: Typeable a => a -> IO (Reference a Concrete)
reference x = Reference <$> (Concrete x <$> newUnique)

It seems to work, but I needed:

transition :: forall r. ForallF Ord r => model r -> cmd r -> resp r -> model r 

Which is terrible to work with, but maybe we can revisit this approach when GHC gets qualified contexts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants