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

Consider using a composition based encoding for some type classes to avoid implicit collisions #2400

Open
LukaJCB opened this issue Aug 14, 2018 · 1 comment

Comments

@LukaJCB
Copy link
Member

LukaJCB commented Aug 14, 2018

We've already adopted this pattern for a few of our type classes to avoid the well known problem that inheritance based type classes bring. All of cats-mtl, as well as Representable, Parallel and NonEmptyParallel already make use of this encoding and can therefore be safely used with the other more canon type classes.

If we look closely at the cats typeclass diagram, we can see which of our type classes could potentially benefit and the important ones seem to be Traverse, CoflatMap and Distributive, which all extend Functor. Another candidate could be Alternative, which one might want to use together with Monad, though I think it's less of a problem, since you can just require MonoidK instead.
And even less urgent, Monad currently has 3 subclasses, Bimonad, MonadError and CommutativeMonad. There could potentially be an issue if you wanted two of those together, but I think it's highly unlikely.

I think we could provide this enhancement without breaking source compatibility and should think about it for our next major version :)

@LukaJCB LukaJCB changed the title Consider using a composition based encoding for type classes to avoid implicit collisions Consider using a composition based encoding for some type classes to avoid implicit collisions Aug 14, 2018
@LukaJCB LukaJCB added this to the 2.0 milestone Aug 14, 2018
@LukaJCB
Copy link
Member Author

LukaJCB commented Aug 14, 2018

A fairly old PR that does part of the work can be found here: #1379

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant