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

Add auto-widen/auto-narrow implicits #3434

Closed
LukaJCB opened this issue May 27, 2020 · 3 comments · Fixed by #3436
Closed

Add auto-widen/auto-narrow implicits #3434

LukaJCB opened this issue May 27, 2020 · 3 comments · Fixed by #3436

Comments

@LukaJCB
Copy link
Member

LukaJCB commented May 27, 2020

It can be quite frustrating sometimes to insert widen or narrow calls sometimes just to make the compiler happy, so we thought it could be a good idea to have two little implicits you could import:

implicit def widenFunctor[F[_]: Functor, A, B >: A](fa: F[A]): F[B] = fa.widen

implicit def narrowContravariant[F[_]: Contravariant, A, B <: A](fa: F[A]): F[B] = fa.narrow
@ChristopherDavenport
Copy link
Member

Might be good to try this in a few downstream projects and confirm this doesn't break something.

@djspiewak
Copy link
Member

Add it to something like cats.implicits.variance._ or something like that in 2.2.0. Then take a survey and see how people like it before 2.3.0, when we could move it to the global.

@djspiewak
Copy link
Member

So as a random datapoint… I added these implicits to every scope in https://github.com/precog/quasar. Everything compiled just fine before and after. There was a 12% performance hit (which is actually a bit less than I was expecting) in compile time after everything was warmed up. To be clear, quasar makes very aggressive use of implicit search across a large section of the codebase, as well as some very complicated type inference, so it probably represents a worse case scenario in terms of compiler performance impact of this change.

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

Successfully merging a pull request may close this issue.

3 participants