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

Make useForever polymorphic rather than speciailising it to Nothing #3748

Conversation

george-wilson-rea
Copy link

I'd prefer if I could pick a type for this, eg. ExitCode.

I write apps like this:

class MyApp extends IOApp {
  def run(args: Args): IO[ExitCode] =
    for {
      config <- readConfig
      otherStuff <- setUpOtherStuff(config)
      ec <- httpServer.resource.useForever
    } yield ec
}

and with the Nothing type, the Scala compiler warns me about dead code, but if I use httpServer.resource.use(_ => IO.never[ExitCode]) then it works fine. Hence, I propose changing useForever to work like this.

@durban
Copy link
Contributor

durban commented Jul 20, 2023

I might be missing something obvious, but I tried your example code, and this change did not make the warning disappear: the compiler still inferred ec: Nothing . (On the other hand, using https://github.com/oleg-py/better-monadic-for does make the warning go away, probably because it removes the final map call.)

@djspiewak
Copy link
Member

I concur with @durban: I'm not sure this really helps. The type will still be inferred to Nothing in unascribed cases, which in turn recreates the problem. There are also a number of cases that I can't quite remember (I think only on Scala 2.12?) where the Nothing encoding actually works a lot better than [A] A, even though they should be equivalent.

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 this pull request may close these issues.

3 participants