-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eq instance is shady #143
Comments
We could have a The simple way: data SomeAsync = forall a. SomeAsync (Async a)
instance Ord SomeAsync where
compare (SomeAsync (Async t1 _)) (SomeAsync (Async t2 _)) = compare t1 t2 Alternatively, we could do this: -- Any instead of a proper existential so this can unpack
data Async a = Async
{ asyncThreadId :: !ThreadId
, _resVar :: !(TMVar (Either SomeException Any))
, _resMod :: (Any -> a) }
instance Functor Async where
fmap f (Async tid rv g) = Async tid rv (f . g)
-- Note that <$ replaces the function instead of adding onto it
x <$ Async tid rv _ = Async tid rv (const x)
data SomeAsync = SomeAsync_ !ThreadId !(TMVar (Either SomeException Any))
instance Ord SomeAsync where
compare (SomeAsync tid1 _) (SomeAsync tid2 _) = compare tid1 tid2
pattern SomeAsync :: MyAsync a -> SomeAsync
pattern SomeAsync x <- ((\(SomeAsync_ tid mv) -> MyAsync tid mv (const ())) -> x)
where
SomeAsync (MyAsync tid tmv _) = SomeAsync_ tid tmv Another variation on that last is to make |
Not a big fan of |
We should have that, yes, but I think sometimes people want to be able to do things like use |
Ok, fair point. |
|
Not to leave this hanging indefinitely - basically I consider this "bug" to be something of a technicality. If we fix it, the cure better not be worse than the disease, and the disease is pretty mild IMO. |
That doesn't make any sense to me. I think it would be better to remove the
Eq
andOrd
instances and just provide custom comparison operations that explicitly operate only on the thread IDs.The text was updated successfully, but these errors were encountered: