-
Notifications
You must be signed in to change notification settings - Fork 21
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
Adding branch
to the class definition
#74
Comments
I've always wanted to add
I think the comparison with |
This set of laws probably doesn't need to be clever. Here is a pretty dumb law that makes
:) But it feels so unsatisfactory! |
I see. I'm actually of the mind that the greater expressive power is nice: is there any reason why we wouldn't want that? I suppose it would make the case that Do we know what the free construction would look like with Personally, anything I've done with Selectives so far has been without using the class (for reasons), so I've always favoured |
There is no particularly good reason. I was initially interested in studying the simplest possible primitive, which comes in the form of
That would depend on the set of laws. If we include the following pretty natural law
then we'll be able to reassociate all branching expressions into lists, much like we do with That is any expression could be rewritten into |
I think it's possibly better called commutativity? Yes, this is one law I have listed down for |
I think it is probably the case that there are no examples of Selective functors that cannot implement |
Yes, "commutativity" (of
There are no |
I meant more are there any existing instances that couldn't be commutative, I guess? |
Sure, any free selective functor. It's an instance of the class after all :) For example: https://github.com/snowleopard/selective/blob/main/src/Control/Selective/Rigid/Free.hs |
And also any |
That doesn't seem right to me. For example, |
Ah, fair. Yes I was thinking about Applicatives where the order of effects matters More precisely then, it doesn't work for |
If you think it's worthwhile, I could probably dedicate some "tube time" to thinking about laws that might involve |
That sounds good, thanks! Here is one possible plan that seems to work:
It's sad that this plan involves breaking all users of the library (they'll have to redefine their instances via |
yeah, the break is annoying. If only Haskell had a rewrite tool for stuff like this (Scala has One helpful mitigation would be putting in |
The
branch
operation can be implemented efficiently on its own, andselect
can be efficiently implemented in terms of it. This is similar toApplicative
's(<*>)/liftA2
for which a more efficient implementation may exist with one compared to the other. I propose doing something similar withSelective
such that:At the very least, adding
branch
to the class would enable a more efficient definition to be given, even if theMINIMAL
is not used.This is done for
Applicative
with(*>)
,(<*)
;Alternative
withmany
andsome
;Monad
with(>>)
.The text was updated successfully, but these errors were encountered: