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

Is concurrent Alternative instance for Task|Future Monad lawful? #203

Closed
safareli opened this issue Nov 21, 2016 · 4 comments
Closed

Is concurrent Alternative instance for Task|Future Monad lawful? #203

safareli opened this issue Nov 21, 2016 · 4 comments
Labels

Comments

@safareli
Copy link
Member

safareli commented Nov 21, 2016

My initial intuition was that (as of ap = <*>) Alternative intance of Task|Future Monad should be something like this (from purescript-aff) and it should not be implemented using never and race. but today i came across briancavalier/creed#92 and there Alternative is implemented using never and or(aka race). After thinking for a while it looks lawful, only issue i see (which actually might not be an issue), is that with distributivity law x.ap(f.alt(g)) == x.ap(f).alt(x.ap(g))

  • in left branch, function from either f or g will be called
  • in right branch, function from both f or g will be called

But as function in g should be pure it might not be an issue? If that's an issue, then Maybe also has this same issue (which I think is not present in Haskell because of laziness)

possibly related issues:

@safareli
Copy link
Member Author

@jdegoes @garyb you have been maintaining Purescript-Aff, maybe you have an answer

@jdegoes
Copy link

jdegoes commented Nov 21, 2016

The Alternative instance of Task|Future must run the first, if it fails, run the second — in sequence.

The Alternative instance for a Parallel must run both, at the same time, and return the first one which succeeds.

@safareli
Copy link
Member Author

@jdegoes yes, that was my initial intuition, but which law is reason for that?

@jdegoes
Copy link

jdegoes commented Nov 23, 2016

The laws are here: https://en.wikibooks.org/wiki/Haskell/Alternative_and_MonadPlus

They don't look like they force these, but they look compatible with them. Good question though.

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

No branches or pull requests

2 participants