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 removing possibility to widen effect in Resource#useForever #1336

Closed
kubukoz opened this issue Oct 19, 2020 · 3 comments · Fixed by #1493
Closed

Consider removing possibility to widen effect in Resource#useForever #1336

kubukoz opened this issue Oct 19, 2020 · 3 comments · Fixed by #1493
Assignees

Comments

@kubukoz
Copy link
Member

kubukoz commented Oct 19, 2020

Because of a mix of variance, widening and Nothing, this code doesn't compile:

object Demo extends IOApp.Simple {

  val run: IO[Unit] = {
    val resource: Resource[IO, Unit] = ???

    resource.useForever
  }

}
polymorphic expression cannot be instantiated to expected type;
 found   : [G[x] >: cats.effect.IO[x]]G[Nothing]
 required: cats.effect.IO[Unit]

If you annotate it as useForever[IO], it works. A possible solution to this might involve removing the G[x] >: F[x] parameter in useForever.

@RaasAhsan
Copy link

I've ran into this problem with other functions like allocated as well (though surprisingly they were all on Dotty). Almost every Resource function widens F to G, but how useful is that in practice? Maybe there's something in fs2, but I've never actually seen or used it before.

@kubukoz
Copy link
Member Author

kubukoz commented Oct 20, 2020

Resource was made covariant in #731, I think it might be useful when someone's F is IO[SpecificException, *] and they want to automatically upcast it to IO[Throwable, *], for example. See #617

I think we can remove the type annotation in useForever for some reason (the REPL allowed me to do it) but not for allocated. If we keep that variance, that is.

@RaasAhsan
Copy link

Ahh, that makes sense, thanks for the context. I'm one of those IO-only users :) I'll post some of the failing Dotty snippets here later because I think it's related but it does typecheck in 2.13.

@SystemFw SystemFw self-assigned this Dec 8, 2020
@SystemFw SystemFw linked a pull request Dec 10, 2020 that will close this issue
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.

4 participants