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 Alt, Plus, Alternative #92

Merged
merged 1 commit into from
Nov 19, 2016
Merged

Add Alt, Plus, Alternative #92

merged 1 commit into from
Nov 19, 2016

Conversation

briancavalier
Copy link
Owner

Add FL 2.1 implementations and tests: Alt, Plus, Alternative. The implementations are trivial--they're rally just aliases for or and never. This means that for 1.x, Monoid and Alt are basically the same thing. For 2.0, we can implement a value-based Monoid.

I found that the fantasyland-laws tests were wrong: they were not calling the laws correctly. The laws are manually curried, and we were calling them with multiple args, so the tests weren't actually verifying anything useful O.o. Mocha was no help, since it's perfectly content to let you write tests with no assertions even when they return something other than a promise. That's also why nyc/istanbul wasn't counting coverage: because the tests weren't really calling any creed code. Fun, eh?

@briancavalier briancavalier changed the title Add Alt, Plus, Alterative Add Alt, Plus, Alternative Nov 19, 2016
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 687f9ef on add-fl-alt-plus into 458d790 on master.

@davidchase
Copy link
Contributor

👍 LGTM

@safareli
Copy link

I think this is not quite valid instance for Monadic Promise see fantasyland/fantasy-land#203

@briancavalier
Copy link
Owner Author

@safareli I debated whether parallel or left catch was the correct Alternative instance, and honestly, I'm still not sure. Your comment from fantasyland/fantasy-land#203, though, seems like it might be the most practical reason to pick left catch:

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

I had been thinking the same as you, though, that it doesn't matter from the standpoint of the laws (though it is wasteful), as long as g is pure.

@jdegoes later comment makes me think there has to be another reason that I'm not seeing. Can you help me understand it a bit better before I go down the path of changing it? Thanks!

@safareli
Copy link

I think, if you have both monadic and non monadic version of Future, in monadic one you should be have sequential Alternative instance and in non monadic one parallel, but don't know if there is any law which restricts to not make monadic one with parallel Alternative instance. maybe @jdegoes can help, but general intuition is that if structure is a Monad it should be sequential.

@briancavalier
Copy link
Owner Author

@safareli Yes, I had the same general intuition (Monad should imply sequential). However, in the course of trying to figure out which way to go with this PR, I ran into the discussions around Haskell's MonadOr and MonadPlus debate. The gist is that there are some monads where Left Distribution is more natural and some where Left Catch is more natural. Additionally, there may even be some monads where both are feasible. And at least so far, both do seem reasonable to me for promises.

Do you or @jdegoes have any thoughts on the Haskell MonadOr/MonadPlus situation? Is it possible that Fantasy Land will explore a direction like Haskell to allow for both?

@jdegoes
Copy link

jdegoes commented Dec 6, 2016

I agree the distinction is useful, and I think you could implement parallel left catch semantics for a monad without breaking any laws. Both seem reasonable for a future.

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.

5 participants