Scala, a functional language for the JVM and JavaScript runtime, has recently been upgraded to version 3.0 with a new type system, new language features, and a number of syntactic improvements. Thinkstock’s editor-in-chief described the upgrade as a “complete overhaul”.
Scala 3, released in production on May 14, has both JVM and JavaScript running mechanisms and is positioned as a library for building high-performance systems with access to the ecosystem. The Scala 3 documentation can be found here.
New language features in Scala 3:
- In an implicit improvement to Scala 2, terms of use can be specified by type, freeing function signatures from the term variable names that are never explicitly mentioned.
- A given instance
Allowing programmers to determine typical values for a type makes programming a type class more straightforward without giving away implementation details.
- Extension methods
It is now built directly into the language for better error information and improved type reasoning. * The implicit Conversion has been redesigned to Conversion, an instance of the type class.
- The context function feature makes context abstractions first-class citizens.
- If an implicit parameter cannot be resolved by the compiler, an import recommendation is provided to resolve the problem.
Type system improvements in Scala 3:
- Enums, or enumerations, were redesigned to blend well with case classes to form a new standard for expressing algebraic data types.
- Opaque type aliases allow developers to hide implementation details without affecting performance.
- Cross and union types can express type constraints outside the inheritance hierarchy.
- Polymorphic function types can abstract functions that accept type parameters in addition to value parameters. * Type lambdas are type-level functions that can be passed as type arguments without the need for auxiliary type definitions.
- Scala 3 supports matching on type, rather than encoding type-level calculations using implicit parsing.
Object-oriented programming features in Scala 3:
- Attributes are closer to classes and can now accept parameters
, making them more powerful as tools for modular software decomposition.
- Open classes
Requires the library designer to mark classes as open. * Practical qualities of realization behavior sometimes should not be part of the type of inference. In Scala 3, these traits can be marked as transparent, hiding inheritance from the user.
- Explicit NULL moves NULL out of the type hierarchy to statically catch errors.
Scala 3 also provides metaprogramming tools, including compile-time operations, referenced code blocks, and the ability to reduce numbers and methods at compile timeAn inline function
Other syntax improvements in Scala 3:
- Optional braces support a nonintrusive, indented sensitive programming style.
new
Keywords are now optional.- Type-level wildcards from
_
Instead of?
。 - Implicit and its syntax have been heavily modified.