Skip to content
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

Refactor FirstToFinish and LastToFinish instances #3850

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

coot
Copy link
Contributor

@coot coot commented Jun 29, 2022

No description provided.

coot and others added 2 commits June 29, 2022 08:51
Deriving a semigroup instance via 'Alt' for 'IO' relies on 'IO'
'Alternative' instance, which is not what we want.  We want 'race`
semantics instead.

The drawback is that one needs to specify the
'Semigroup (FirstToFinish m a)' constraint, when 'm' is abstract, as in
the tests.
deriving Foldable via (Alt m)
deriving Contravariant via (Alt m)


instance Semigroup (FirstToFinish IO a) where
FirstToFinish a <> FirstToFinish b = FirstToFinish $ either id id <$> race a b
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use similar approach to LastToFinish.

@@ -203,6 +204,8 @@ runMux :: forall m mode.
, MonadTime m
, MonadTimer m
, MonadMask m
, forall a stm. stm ~ STM m => Semigroup (FirstToFinish stm a)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a type alias for this constraint if possible.

@coot coot removed the networking label Dec 18, 2023
Copy link
Contributor

@bolt12 bolt12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between LastToFinish and LastToFinishM?

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

Successfully merging this pull request may close these issues.

2 participants