-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 Selective #2745
Comments
I think Selective is super interesting and I can't wait to dive into it more fully. trait Selective[F[_]] extends Apply[F] {
def selective[A, B, C](feab: F[Either[A, B]])(fc: F[C]): F[Either[(A, C), B]]
def select[A, B](feab: F[Either[A, B]])(ff: F[A => B]): F[B] =
map(selective(feab)(ff))(_.fold({ case (a, f) => f(a) }, identity))
} modulo the inheritance bit. |
I'm planning to take a stab at this today based on @johnynek's formulation. Can't guarantee I will get anywhere with it though. |
Not to discourage you @cb372, but I think it's a good idea to take our time and be patient with this. It's a very new and experimental abstraction, that could probably use some time discussing how to implement it, especially with how it fits in the cats hierarchy :) In other news, I'm super excited for this, the paper is really awesome, and I can some really cool things happening in this space in the future 🎉 |
One idea might be to add some of the more interesting selective functions to Validated to see if we think those are useful. Then consider are there interesting cases we care about beyond Validated. |
@LukaJCB How would you like to proceed with this? We can hold off on doing any more work on that PR, if you want some time to explore other designs. Hopefully the PR is at least useful as a reference/proof of concept even if it doesn't end up getting merged. /cc @hamishdickson |
One way to make the member Applicative more ergonomic would be to add an implicit: implicit def applicativeFromSelective[F[_]](implicit F: Selective[F]): Applicative[F] Which we you can import or possibly be a low priority on Applicative if we can do it in a binary compatible way. |
I very much appreciate the PR, it's really great work! Maybe it might make sense to think about a separate module for now? So that people can use it in their projects and experiment? I think it's not unreasonable to expect us to want to change something about any |
That definitely sounds like a good solution about the separate module @LukaJCB - are you thinking some kind of
I think I'm missing something here - the laws and some of the combinators in the paper require It's a great abstraction - I'm really looking forward to seeing what people build with it! :) |
I think we could express associatvity and distributivity without |
Another thing worth discussing; should the second argument be strict, by-name or use Edit: if we look at precedence, all of |
I think we should set up a new repo |
I have thought of a yet another thing we need to consider, what about the |
@LukaJCB doesn’t that defeat the purpose of Parallel. We want to go from Either to Validated or IO to IO.Par. Cases like that are the motivation of the typeclass. Also, in what cases are Selective map2 not what Applicative map2 would want? In IO and Validated map2 is not Parallel of course. |
I'll try and set up a new I'm still not sure about @LukaJCB's idea of extending |
@cb372 I'm sorry if I created confusion, I just said I want to split up |
Ah ok that makes more sense 😄 |
@johnynek, I guess you're right since there is no |
So what if I want to have a statically analyzable |
I've set up https://github.com/cb372/cats-selective (just in time before @LukaJCB explodes with excitement, based on his recent Twitter output) It's still very bare-bones, pretty much the code that was in the PR, but it should be a good base for experimentation. I'm happy to transfer it to typelevel or leave it where it is. Currently it's missing a licence. Is there a recommendation here? I see cats-tagless is Apache 2.0 but cats-mtl has a COPYING file. |
@LukaJCB This property does hold for many selective functors, and we call such selective functors "rigid" in the paper. For example, all monads are rigid because |
@cb372 I think mirroring Cats' usage of MIT license is probably easiest :) |
@cb372 , this is awesome. Do you plan to release it to maven central through sonatype? Another option is to resurrect the idea of a On a side note, |
OK I'll put an MIT licence on it 👍 Sure, I can set up sonatype publishing when necessary. I'll have to change the organisation to my own |
I found myself in need of this recently. It'd be great if we could move this forward in cats. |
Here's a real-world, open-source Selective use case: typelevel/cats-parse#101 |
I think it is pretty clear that Selective is as useful as many of the typeclasses in cats. One thing I would vote for: I don't see the value in making a default implementation from Selective using Apply. If you don't get laziness in the second parameter, I don't see a big win of Selective and would rather encode such eager methods directly on Apply. I think the paper calls these "tight". I think we should have the laws require tightness. |
https://www.staff.ncl.ac.uk/andrey.mokhov/selective-functors.pdf
Note the paper gives some interesting examples of things that don't have Monad but do have Selective, e.g. Validated.
The text was updated successfully, but these errors were encountered: