-
-
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
Attempt to implement type classes without inheritance #8
Comments
I seem to recall that the main reason scalaz didn't take this approach was because of the extra overhead of all of the implicit chaining (the extra function calls and instance allocations). I'm not sure how much of a problem this is in practice. Also for what it's worth, I think that I heard @tpolecat say that scalaz has considered taking this approach in scalaz 8.0. |
I like the idea in principle but I also worry about allocations. Seems like it's worth prototyping. |
I'm pretty skeptical (as I said on #71). I think the nested field lookups for every single method call will be really bad for performance. I think this strategy is a non-starter for Spire and Algebra. If we did some testing and found that for Cats it would be OK, then we could move to it, but would have to drop interop with Algebra and Spire. I'm pretty reluctant to do this but willing to talk about it. |
@non I understand and share your concern regarding the performance of using evidence. I will try to benchmark the two approach at some point. Should I close this ticket until we have evidence that a non inheritance base approach provide good performance? |
I just added the "on hold" label. I don't think we need to completely close the issue if it's still under consideration. If it sits here and rots for months then we can close it out. |
@ceedubs sounds like a plan |
Sounds good to me too. |
people are experimenting removing inheritance in scalaz 8: |
I tried both approaches in the lead up to Scalaz 7, but found it the inheritance free version was unworkable. def foo[F: Functor]
def bar[F: Monad] = foo // will not typecheck Adding an "upcasting" implicit from |
@julien-truffaut there hasn't been any discussion on this issue. Do you want to keep it open? Are there concrete proposals to move forward? |
No we didn't have any discussion regarding this issue recently. So it is better to close it for the moment. I think scalaz 8 is looking toward this approach, we can always monitor how does it go. |
in scalaz and cats, type classes are defined as trait with inheritance to express facts like all
Monad
are anApplicative
. This leads to some ambiguous implicit resolutions and as far as I know, the solution is to create a hierarchy of traits to guide implicit search. It also creates ambiguous implicit when you have two imports that brings the same implicit in scope e.g.I wonder if it would be possible and desirable to implement type classes using abstract class and implicit evidence to express the hierarchy between two type classes:
I haven't tried this technique extensively, so it might in fact causes more issues that inheritance. However, I thought it make sense to discuss this option since you are just starting cats.
The text was updated successfully, but these errors were encountered: