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

Added Monad, MonadPlus, and MonadFix instance to Concurrently #71

Closed
wants to merge 1 commit into from

Conversation

ChristopherKing42
Copy link

@ChristopherKing42 ChristopherKing42 commented Dec 11, 2017

The Monad instance is in fact compatible with the Applicative instance. In as >>= asb, it will run concurrently if asb is lazy (such as used by ap) and sequential when strict.

Closes #69.

This is just tentative. I decided to implement it, since it did not take much coding. Feel free to deny this pull request.

@ChristopherKing42
Copy link
Author

ChristopherKing42 commented Dec 11, 2017

This can also technically be done with mfix instead of unsafeInterleaveIO, if you're more comfortable with that, but its a little trickier.

Actually, it wasn't too hard: ChristopherKing42@ab78a37. It was slightly less efficient though then directly using an unsafe operation. If you prefer this version though, I can make it a pull request.

@ChristopherKing42
Copy link
Author

ChristopherKing42 commented Dec 12, 2017

Oh whoops. This closes #69, not 70.

The Monad instance is in fact compatible with the Applicative instance. In as >>= asb, it will run concurrently if asb is lazy (such as used by `ap`) and sequential when strict

Close simonmar#69
@simonmar
Copy link
Owner

It's quite worrying that this connects concurrency to laziness. I have strong reservations about how easy this is to program with, and how maintainable the code is that uses it. Any time the programmer has to understand evaluation order I think we're in deep trouble. The places I know where this has caused problems: circular programming and parallel Strategies.

It's also concerning that this would be disturbingly easy to use. A lot of the time you could just use the Monad and get magic concurrency, but sometimes it would go wrong, and when it goes wrong it'll be really hard to debug.

(on the other hand you could level some of these concerns at Haxl, but at least there we're up front that there's magic happening. The async package so far is very explicit about where the concurrency happens, so allowing some magic in changes the game in a significant way.)

If there's a lot of support for this then I'm not 100% against it, but for now I'm leaning towards reject. I wouldn't be against to exposing enough internals of async so that you could build this in a separate package, though.

@ChristopherKing42
Copy link
Author

Yeah, this was mostly just to show it was possible. Sufficient internals are exposed actually. All that if needed is Concurrently, runConcurrently, and concurrently, which is already exposed.

@ChristopherKing42
Copy link
Author

Actually, it wasn't a valid monad anyways. Oh well.

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

Successfully merging this pull request may close these issues.

2 participants