8000 Move syntax type bounds to methods by umazalakain · Pull Request #8 · umazalakain/errata · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Move syntax type bounds to methods #8

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

Merged
merged 1 commit into from
Jan 4, 2024
Merged

Conversation

umazalakain
Copy link
Owner

Better discoverability, but it demands type parameters from the user

@ShahOdin
Copy link
Contributor
ShahOdin commented Dec 30, 2023

ideally as a cats-accustomed user of this library, I'd like to have the following set of syntax permutations available to me:

  • only namespaced syntax
  • only non-namespaced syntax
  • a mix of namespaced and non-namespaced syntax. (use namespaced only if I have to, ie liftTo)

I tested the code on this branch with this app:

import cats.effect.{ExitCode, IO, IOApp}
import errata.*
import errata.instances.*

object catsInteroperability extends IOApp{
  val error: Throwable = new Throwable("Boom!")
  val either: Either[Throwable, Unit] = Left(error)

  /*use only namespaced syntax, compiles, IDE happy*/
//  def run(args: List[String]): IO[ExitCode] = {
//    import errata.syntax.namespaced.*
//    error.withErrata.raise[IO, Throwable, Unit] *>
//      either.withErrata.liftTo[IO, Throwable] as
//      ExitCode.Success
//  }

  /*use only non-namespaced syntax, compiles, IDE happy*/

//  def run(args: List[String]): IO[ExitCode] = {
//    import errata.syntax.all.*
//    error.raise[IO, Throwable, Unit] as
//      ExitCode.Success
//  }

  /*use both namespaced and non-namespaced syntax. compiles. IDE unhappy with liftTo*/
  def run(args: List[String]): IO[ExitCode] = {
    import errata.syntax.all.*
    import errata.syntax.namespaced.*
    error.raise[IO, Throwable, Unit] *>
      either.withErrata.liftTo[IO, Throwable] as
      ExitCode.Success
  }

}

observations:

  • This all compiles.
  • IDE is happy with all of them except the last mixed form
  • too much explicit types everywhere

I also tried doing the equivalent with the version on main. I might be missing something, but I couldn't even get the first example working. Ie, I had to manually specify everything, plus I couldn't mix and match name spaced and non name spaced syntax:

import cats.effect.{ExitCode, IO, IOApp}
import errata.instances.*

object catsInteroperability extends IOApp{
  val error: Throwable = new Throwable("Boom!")
  val either: Either[Throwable, Unit] = Left(error)
  def run(args: List[String]): IO[ExitCode] = {
    import errata.syntax.namespaced.*
    RaiseSyntax[IO, Throwable, Throwable](error.withErrata).raise[Unit] *>
      EitherLiftSyntax[IO, Throwable, Throwable, Unit](either.withErrata).liftTo as
      ExitCode.Success
  }
}

Better discoverability, but it demands type parameters from the user
@umazalakain
Copy link
Owner Author

Hey @ShahOdin!

Sorry it took me so long to get back to you on this one. I tried making both syntaxes work simultaneously, but it looks like it's going to be rather complicated. I will open a separate ticket and work on it.

Meanwhile in this PR the type bounds are moved into methods. The amended commit minimises the type parameters required from the user. The new variance stuff you introduces also makes some type parameters unnecessary.

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.

2 participants
0