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

Add Monad instance for Concurrently #48

Closed
TravisWhitaker opened this issue Sep 18, 2016 · 2 comments
Closed

Add Monad instance for Concurrently #48

TravisWhitaker opened this issue Sep 18, 2016 · 2 comments

Comments

@TravisWhitaker
Copy link

In light of the ApplicativeDo extension made available in GHC 8.0.1, I'd like to propose the following Monad instance for Concurrently.

instance Monad Concurrently where
    return = pure
    x >>= f = Concurrently $ runConcurrently x >>= (runConcurrently . f)

Where bind simply runs two Concurrently actions sequentially. This should allow one to write things of the form:

do x <- a
   y <- b
   f x y

The desugared expression will require join, and should allow f to wait on a and b, which may run concurrently.

@simonmar
Copy link
Owner

Isn't this the same as the Monad instance that was removed in bb1d405? It didn't satisfy the Monad laws so it was removed.

@TravisWhitaker
Copy link
Author

Hmm, that's tricky indeed; I definitely would've been tripped up by that at some point.

For anyone else who wonders why this isn't possible #26 discusses the implications of (<*>) /= ap and #38 from either includes discussion of how Haxl deals with this issue.

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

No branches or pull requests

2 participants