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

Somewhat annoying to get at rethrow syntax due to invariance #2561

Closed
djspiewak opened this issue Oct 16, 2018 · 1 comment
Closed

Somewhat annoying to get at rethrow syntax due to invariance #2561

djspiewak opened this issue Oct 16, 2018 · 1 comment

Comments

@djspiewak
Copy link
Member

MonadError is invariant in E, which is problematic in turn because it means that catsSyntaxMonadErrorRethrow will not infer on Either[E, A] where E <: Throwable, which is vastly far and away the most common case. For example, if you have an expression that produces F[Either[RuntimeException, A]], you might reasonably expect that rethrow would be available syntax on such a value (at least, I did). It won't work though, and it's quite difficult to tease out why this is the case.

We can either make MonadError contravariant in E (which I believe would cause a cascade of problematic changes, so I don't recommend it), or we can loosen the constraints on catsSyntaxMonadErrorRethrow. Something like:

implicit final def catsSyntaxMonadErrorRethrow[F[_], E2, E1 <: E2, A](fea: F[Either[E1, A]])(implicit F: MonadError[F, E2]): MonadErrorRethrowOps[F, E2, A]

Or the latter, which is likely to infer slightly better:

implicit final def catsSyntaxMonadErrorRethrow[F[_], E1, E2, A](fea: F[Either[E1, A]])(implicit F: MonadError[F, E2], ev: E1 <~< E2): MonadErrorRethrowOps[F, E2, A]
@LukaJCB
Copy link
Member

LukaJCB commented Jul 3, 2019

Closed by #2880

@LukaJCB LukaJCB closed this as completed Jul 3, 2019
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

No branches or pull requests

2 participants