Is there a Scala 3 specific standard library or is it just inherited from Scala 2?

347 Views Asked by At

Is it the case that Scala 3 uses all the collections from Scala 2 standard library? (What elements Scala "standard library" consists of?)

Is there any Scala 3 specific "standard library"?

Are there plans to reimplement Scala 2 libraries to Scala 3?

I was looking for an implementation of an immutable list in Scala 3 and I realized that there seems to be no such thing in the dotty repo.

I was expecting to find an implementation of Scala 2 list in the dotty repo as well.

2

There are 2 best solutions below

2
Jörg W Mittag On

The standard library is shared between Scala 3 and Scala 2.13 and is maintained as part of Scala 2.13.

The standard library was refactored / re-engineered such that it only uses language features that exist in both Scala 2.13 and Scala 3.

(Note: when I write "Scala 3" and "Scala 2.13", I mean the implementations with those version numbers. The Scala Language Specification does not say anything about how the standard library is implemented.)

1
Dmytro Mitin On

Scala 2.13 standard library is a part of Scala 3 standard library

"org.scala-lang" % "scala-library" % "2.13.10"

https://mvnrepository.com/artifact/org.scala-lang/scala-library

https://search.maven.org/artifact/org.scala-lang/scala-library/2.13.10/jar

https://github.com/scala/scala/tree/2.13.x/src/library/scala

The Standard Library

One notable example is the Scala 2.13 library. We have indeed decided that the Scala 2.13 library is the official standard library for Scala 3.

Let’s note that the standard library is automatically provided by the build tool, you should not need to configure it manually.

https://docs.scala-lang.org/scala3/guides/migration/compatibility-classpath.html#the-standard-library

But there is also additional Scala 3 specific part of Scala 3 standard library (packages scala.deriving, scala.compiletime, scala.quoted, scala.reflect, scala.runtime, scala.util, scala.annotation)

"org.scala-lang" % "scala3-library_3" % "3.2.2"

or

"org.scala-lang" %% "scala3-library" % "3.2.2"

https://mvnrepository.com/artifact/org.scala-lang/scala3-library

https://search.maven.org/artifact/org.scala-lang/scala3-library_3/3.2.2/jar

https://github.com/lampepfl/dotty/tree/main/library/src/scala