-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
Why doesn't Future implement the Alternative interface by default? #290
Comments
Hi @gwn.
There is no need for that. It's a very good question - or, several questions, rather. And Fluture is a good place to ask them: it's a prominent implementation of a time-dependent Applicative.
Practically, because it doesn't have Monad, so you cannot use
If we would implement Monad on ConcurrentFuture, the implementation of Applicative must become sequential. That would mean ConcurrentFuture is no longer concurrent. ;) Background: In case a type has Monad, the Applicative instance must behave as if derived from
I believe it has to do the way the Applicative instance is affected in conflicting ways by the Monad or Alternative instance on time-dependent types. The way I've come to understand it, implementing both Monad and Alternative on a time-dependent Applicative, would mean that there are then two conflicting yet valid implementations of Applicative which the type must implement. Though now that you ask, I can't really back that up. Up until this point, I had assumed that the conflict arises from the Alternative instance dictating the behavior of I currently cannot provide a good reason as to why Future can't have Alternative as well as Monad - be it with sequential I would like to ask @safareli for some input here. Intuitively, it seems logical to me that a type is either fully sequential, or fully parallel. But I don't see any mention of the relationship between Alternative and Applicative that would make that apparent. |
Ah. Thank you for the great explanation, @Avaq. You really made everything clear. I examined the issue you referred to and all other related issues -as well as the ones from Fantasy Land and other future libraries- and now have an understanding of the matter, which I realized to be a bit complicated. (Makes me happy as it shows that my question is not a silly one indeed :) I'm convinced for now that the separate types approach makes sense, so I'll happily make do with ConcurrentFuture for my algebraic needs. Closing this; though further input will of course be appreciated. |
I don't want to rely on Future specific methods such as
race
andparallel
when there are lovely generic alternatives such asalt
,traverse
etc..I'm asking this question because my understanding of the "time-dependent applicatives" is limited; as I'm new to functional programming.
I came across the following explanation in the README of the concurrify library:
I infer from the explanation above that Future doesn't have concurrent behavior by default whether we use it as a monad or an applicative. Why is this the case? Is this the canonical implementation of this type (if there is such a thing)?
What is preventing me from using ConcurrentFuture all the time instead of a Future? Is the sequential approach more performant / lightweight / safe / simple by default or something like that?
Can't we get sequential behavior in ConcurrentFuture too if we use it as a monad?
I apologize for my ignorance on the topic. I feel that these questions are probably not really about Fluture. I'm just looking for quick pointers instead of in-depth explanations about the nature of these types and related laws.
The text was updated successfully, but these errors were encountered: