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

Scala-3: Use Opaque Types. #3834

Closed
wants to merge 4 commits into from
Closed

Scala-3: Use Opaque Types. #3834

wants to merge 4 commits into from

Conversation

diesalbla
Copy link
Contributor

@diesalbla diesalbla commented Mar 23, 2021

Scala-3 comes with its own zero-cost Newtype implementation, as Opaque Types. This is an improvement over existing case classes, or Newtype encodings we are using.

In this commit, we bifurcate the IdT wrapper in two implementations: the existing one goes to the Scala-2.x branch, a new one with newtype is used on the new.

#3835

@rossabaker
Copy link
Member

The goal is compelling, but this is 3500 extra lines of code, and maintaining parity across Scala 2 and Scala 3 will be exceedingly difficult. I wonder if there's a less duplicative encoding of this?

@diesalbla
Copy link
Contributor Author

diesalbla commented Mar 29, 2021

The goal is compelling, but this is 3500 extra lines of code, and maintaining parity across Scala 2 and Scala 3 will be exceedingly difficult. I wonder if there's a less duplicative encoding of this?

I doubt we can avoid duplication, since we are writing in two languages. The goal is not just compellingPlus, the sooner we start using features of Dotty, the sooner we can find the minefields and bugs on the language... as I just found some.

Update: I have converted the OptionT case class into an opaque type. Of course, with opaque types all methods are extension methods.

  • One feature of extension methods is that we can group methods that use a same type-class constraint, such as "Functor[F]" or "Monad[F]".
  • One difficulty is that the compiler seems unable to recognise references to other methods, in the same collective, as using the same using Functor[F] (for example).
  • It also seems unable to tell apart a map on the F from a map on the OptionT[F, A].

Currently, this is crashing the Scala 3 compiler. scala/scala3#11499

Scala-3 comes with its own zero-cost Newtype implementation, as Opaque
Types. This is an improvement over existing case classes, or Newtype
encodings we are using.

In this commit, we bifurcate the `IdT` wrapper in two implementations:
the existing one goes to the Scala-2.x branch, a new one with newtype
is used on the new
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