Scala 3 features

Scala 3 features DEFAULT

Scala 3 Overhauls Language for Better Developer Experience

Eight years in the making with 28,000 commits, 7,400 pull requests, and 4,100 closed issues, Scala 3.0 has been released, delivering a "complete overhaul of the Scala language" with new features, updates to the syntax and type systems, and new tools for metaprogramming. The Scala compatibility reference heralds version 3 as a "game changer [...] that will greatly improve the day-to-day experience of every Scala programmer". Scala 3 is binary backwards-compatible with Scala 2.13, but not fully source-compatible. The new Dotty compiler can automatically migrate old code and report any remaining issues.

Scala 3.0 is more concise with its new syntax. The keyword is now optional (similar to Google having introduced this feature in Dart 2.0), as are parentheses in expressions of control structures. Some occurrences of curly braces may be replaced with source code indentation, a well-known feature of Python.

New language features allow developers to directly express their intent with opinionated contextual abstractions: clauses and instances simplify context parameters, extension methods are first-class language citizens, and conversions are now built as instances of the class.

The type system was improved with features such as simplified enums; types that hide implementation details; intersection and union types to provide syntax such as and , respectively; new dependent function types whose result depends on a function's parameters; and built-in type lambdas that once required a compiler plugin in Scala 2.

The enum syntax in Scala 2 was verbose. Consider the following example:

Scala 3 introduces a more concise syntax:

Functional programming has been simplified with the redesign of the contextual abstractions and type system changes. Object-oriented development was also improved with new features such as: accepting parameters and being declared as ; an modifier that explicitly marks classes as open for extension; and in the spirit of encouraging the Decorator design pattern principle, favor composition over inheritance, by providing clauses that define aliases for selected members of an object.

Macros, first introduced in Scala 2.10, was an experimental feature. Scala 3 introduces a set of metaprogramming tools featuring: inlining methods to improve application performance; compile-time operations that may be used with inline methods; quoted code blocks to construct and analyze code; and a reflection API to provide a view of the typed abstract syntax trees including TASTy files. Designed for stability, Scala 3 macros will be compatible with future versions of Scala. However, with this new metaprogramming model, Scala 2.13 macros will require rewriting. In addition, many Scala 2 settings have changed to standardize parameters in Scala 3.

There are new compiler options such as: will ignore compiler errors with code that call Scala 2 macros; will print raw TASTy files; and will enforce the classical syntax. The migration guide details the move to Scala 3 and contains a tutorial on porting a complete Scala 2.13 project to Scala 3.

A Scala 3.0 application may still use a Scala 2.13 library even with macros — unless the non-working macros break the library. The opposite is also true, such that a Scala 2.13 application may use a Scala 3.0 library. The Scala Library Index, AKA Scaladex, lists which libraries are ready for Scala 3.0.

These changes come at a price, however, as some Scala 2.13 source code is incompatible with Scala 3.0. Fortunately, the new compiler includes a migration mode that can automatically migrate Scala 2 code to Scala 3 and report any remaining issues that require manual fixing.

More information on Scala 3 may be found on the what's new section of the website.

The easiest way to get started with Scala 3.0 is with Scastie, Scala’s online IDE, where code may be written and executed directly in the browser. The documentation also demonstrates how to run a "Hello, world" program.

Five weeks after the release, the Scala 3.0 documentation and book are incomplete, and the Scala community is encouraged to contribute.

New Scala releases are expected every six weeks after the 3.0 release. Developers may expect the next release at the end of June 2021.

This content is in the Java topic

Related Topics:
Sours: https://www.infoq.com/news/2021/06/scala-3-overhaul/

Scala 3 Features

The name Scala comes from the word scalable, and true to that name, the Scala language is used to power busy websites and analyze huge data sets. This section introduces the features that make Scala a scalable language. These features are split into three sections:

  • High-level language features
  • Lower-level language features
  • Scala ecosystem features

High-level features

Looking at Scala from the proverbial “30,000 foot view,” you can make the following statements about it:

  • It’s a high-level programming language
  • It has a concise, readable syntax
  • It’s statically-typed (but feels dynamic)
  • It has an expressive type system
  • It’s a functional programming (FP) language
  • It’s an object-oriented programming (OOP) language
  • It supports the fusion of FP and OOP
  • Contextual abstractions provide a clear way to implement term inference
  • It runs on the JVM (and in the browser)
  • It interacts seamlessly with Java code
  • It’s used for server-side applications (including microservices), big data applications, and can also be used in the browser with Scala.js

The following sections take a quick look at these features.

A high-level language

Scala is considered a high-level language in at least two ways. First, like Java and many other modern languages, you don’t deal with low-level concepts like pointers and memory management.

Second, with the use of lambdas and higher-order functions, you write your code at a very high level. As the functional programming saying goes, in Scala you write what you want, not how to achieve it. That is, we don’t write imperative code like this:

That code instructs the compiler what to do on a step-by-step basis. Instead, we write high-level, functional code using higher-order functions and lambdas like this to compute the same result:

As you can see, that code is much more concise, easier to read, and easier to maintain.

Concise syntax

Scala has a concise, readable syntax. For instance, variables are created concisely, and their types are clear:

Higher-order functions and lambdas make for concise code that’s readable:

Traits, classes, and methods are defined with a clean, light syntax:

Studies have shown that the time a developer spends reading code to writing code is at least a 10:1 ratio, so writing code that is concise and readable is important.

A dynamic feel

Scala is a statically-typed language, but thanks to its type inference capabilities it feels dynamic. All of these expressions look like a dynamically-typed language like Python or Ruby, but they’re all Scala:

As Heather Miller states, Scala is considered to be a strong, statically-typed language, and you get all the benefits of static types:

  • Correctness: you catch most errors at compile-time
  • Great IDE support
    • Reliable code completion
    • Catching errors at compile-time means catching mistakes as you type
    • Easy and reliable refactoring
  • You can refactor your code with confidence
  • Method type declarations tell readers what the method does, and help serve as documentation
  • Scalability and maintainability: types help ensure correctness across arbitrarily large applications and development teams
  • Strong typing in combination with excellent inference enables mechanisms like contextual abstraction that allows you to omit boilerplate code. Often, this boilerplate code can be inferred by the compiler, based on type definitions and a given context.

Expressive type system

Scala’s type system enforces, at compile-time, that abstractions are used in a safe and coherent manner. In particular, the type system supports:

In combination, these features provide a powerful basis for the safe reuse of programming abstractions and for the type-safe extension of software.

A functional programming language

Scala is a functional programming (FP) language, meaning:

  • Functions are values, and can be passed around like any other value
  • Higher-order functions are directly supported
  • Lambdas are built in
  • Everything in Scala is an expression that returns a value
  • Syntactically it’s easy to use immutable variables, and their use is encouraged
  • It has a wealth of immutable collection classes in the standard library
  • Those collection classes come with dozens of functional methods: they don’t mutate the collection, but instead return an updated copy of the data

An object-oriented language

Scala is an object-oriented programming (OOP) language. Every value is an instance of a class and every “operator” is a method.

In Scala, all types inherit from a top-level class , whose immediate children are (value types, such as and ) and (reference types, as in Java). This means that the Java distinction between primitive types and boxed types (e.g. vs. ) isn’t present in Scala. Boxing and unboxing is completely transparent to the user.

Supports FP/OOP fusion

The essence of Scala is the fusion of functional programming and object-oriented programming in a typed setting:

  • Functions for the logic
  • Objects for the modularity

As Martin Odersky has stated, “Scala was designed to show that a fusion of functional and object-oriented programming is possible and practical.”

Term inference, made clearer

Following Haskell, Scala was the second popular language to have some form of implicits. In Scala 3 these concepts have been completely re-thought and more clearly implemented.

The core idea is term inference: Given a type, the compiler synthesizes a “canonical” term that has that type. In Scala, a context parameter directly leads to an inferred argument term that could also be written down explicitly.

Use cases for this concept include implementing type classes, establishing context, dependency injection, expressing capabilities, computing new types, and proving relationships between them.

Scala 3 makes this process more clear than ever before. Read about contextual abstractions in the Reference documentation.

Client & server

Scala code runs on the Java Virtual Machine (JVM), so you get all of its benefits:

  • Security
  • Performance
  • Memory management
  • Portability and platform independence
  • The ability to use the wealth of existing Java and JVM libraries

In addition to running on the JVM, Scala also runs in the browser with Scala.js (and open source third-party tools to integrate popular JavaScript libraries), and native executables can be built with Scala Native and GraalVM.

Seamless Java interaction

You can use Java classes and libraries in your Scala applications, and you can use Scala code in your Java applications. In regards to the second point, large libraries like Akka and the Play Framework are written in Scala, and can be used in Java applications.

In regards to the first point, Java classes and libraries are used in Scala applications every day. For instance, in Scala you can read files with a Java and :

Using Java code in Scala is generally seamless.

Java collections can also be used in Scala, and if you want to use Scala’s rich collection class methods with them, you can convert them with just a few lines of code:

Wealth of libraries

As you’ll see in the third section of this page, Scala libraries and frameworks like these have been written to power busy websites and work with huge datasets:

  1. The Play Framework is a lightweight, stateless, developer-friendly, web-friendly architecture for creating highly-scalable applications
  2. Lagom is a microservices framework that helps you decompose your legacy monolith and build, test, and deploy entire systems of reactive microservices
  3. Apache Spark is a unified analytics engine for big data processing, with built-in modules for streaming, SQL, machine learning and graph processing

The Awesome Scala list shows dozens of additional open source tools that developers have created to build Scala applications.

In addition to server-side programming, Scala.js is a strongly-typed replacement for writing JavaScript, with open source third-party libraries that include tools to integrate with Facebook’s React library, jQuery, and more.

Lower-level language features

Where the previous section covered high-level features of Scala 3, it’s interesting to note that at a high level you can make the same statements about both Scala 2 and Scala 3. A decade ago Scala started with a strong foundation of desirable features, and as you’ll see in this section, those benefits have been improved with Scala 3.

At a “sea level” view of the details—i.e., the language features programmers use everyday—Scala 3 has significant advantages over Scala 2:

  • The ability to create algebraic data types (ADTs) more concisely with enums
  • An even more concise and readable syntax:
    • The “quiet” control structure syntax is easier to read
    • Optional braces
      • Fewer symbols in the code creates less visual noise, making it easier to read
    • The keyword is generally no longer needed when creating class instances
    • The formality of package objects have been dropped in favor of simpler “top level” definitions
  • A grammar that’s more clear:
    • Multiple different uses of the keyword have been removed; those uses are replaced by more obvious keywords like , , and , focusing on intent over mechanism (see the Givens section for details)
    • Extension methods replace implicit classes with a clearer and simpler mechanism
    • The addition of the modifier for classes makes the developer intentionally declare that a class is open for modification, thereby limiting ad-hoc extensions to a code base
    • Multiversal equality rules out nonsensical comparisons with and (i.e., attempting to compare a to a )
    • Macros are implemented much more easily
    • Union and intersection offer a flexible way to model types
    • Trait parameters replace and simplify early initializers
    • Opaque type aliases replace most uses of value classes, while guaranteeing the absence of boxing
    • Export clauses provide a simple and general way to express aggregation, which can replace the previous facade pattern of package objects inheriting from classes
    • The procedure syntax has been dropped, and the varargs syntax has been changed, both to make the language more consistent
    • The annotation makes it obvious how you want a method to be applied
    • The method annotation defines an alternate name for the method, improving Java interoperability, and letting you provide aliases for symbolic operators

It would take too much space to demonstrate all of those features here, but follow the links in the items above to see those features in action. All of these features are discussed in detail in the New, Changed, and Dropped features pages in the Overview documentation.

Scala ecosystem

Scala has a vibrant ecosystem, with libraries and frameworks for every need. The “Awesome Scala” list provides a list of hundreds of open source projects that are available to Scala developers, and the Scaladex provides a searchable index of Scala libraries. Some of the more notable libraries are listed below.

Web development

  • The Play Framework followed the Ruby on Rails model to become a lightweight, stateless, developer-friendly, web-friendly architecture for highly-scalable applications
  • Scalatra is a tiny, high-performance, async web framework, inspired by Sinatra
  • Finatra is Scala services built on TwitterServer and Finagle
  • Scala.js is a strongly-typed replacement for JavaScript that provides a safer way to build robust front-end web applications
  • ScalaJs-React lifts Facebook’s React library into Scala.js, and endeavours to make it as type-safe and Scala-friendly as possible
  • Lagom is a microservices framework that helps you decompose your legacy monolith and build, test, and deploy entire systems of Reactive microservices

HTTP(S) libraries:

JSON libraries:

Serialization:

Science and data analysis:

Big data

AI, machine learning

Functional Programming & Functional Reactive Programming

FP:

Functional reactive programming (FRP):

Build tools

Summary

As this page shows, Scala has many terrific programming language features at a high level, at an everyday programming level, and through its developer ecosystem.

previousnext

Contributors to this page:

Sours: https://docs.scala-lang.org/scala3/book/scala-features.html
  1. Barneveld restaurants
  2. Atlantacutlery.com coupon
  3. Biore oily skin
  4. Voldemort anime
  5. Kingston vacation rental

Overview

Scala 3 implements many language changes and improvements over Scala 2. In this reference, we discuss design decisions and present important differences compared to Scala 2.

Goals

The language redesign was guided by three main goals:

  • Strengthen Scala's foundations. Make the full programming language compatible with the foundational work on the DOT calculus and apply the lessons learned from that work.
  • Make Scala easier and safer to use. Tame powerful constructs such as implicits to provide a gentler learning curve. Remove warts and puzzlers.
  • Further improve the consistency and expressiveness of Scala's language constructs.

Corresponding to these goals, the language changes fall into seven categories: (1) Core constructs to strengthen foundations, (2) simplifications and (3) restrictions, to make the language easier and safer to use, (4) dropped constructs to make the language smaller and more regular, (5) changed constructs to remove warts, and increase consistency and usability, (6) new constructs to fill gaps and increase expressiveness, (7) a new, principled approach to metaprogramming that replaces Scala 2 experimental macros.

Essential Foundations

These new constructs directly model core features of DOT, higher-kinded types, and the SI calculus for implicit resolution.

Simplifications

These constructs replace existing constructs with the aim of making the language safer and simpler to use, and to promote uniformity in code style.

  • Trait parameters replace early initializers with a more generally useful construct.
  • Given instances replace implicit objects and defs, focussing on intent over mechanism.
  • Using clauses replace implicit parameters, avoiding their ambiguities.
  • Extension methods replace implicit classes with a clearer and simpler mechanism.
  • Opaque type aliases replace most uses of value classes while guaranteeing absence of boxing.
  • Top-level definitions replace package objects, dropping syntactic boilerplate.
  • Export clauses provide a simple and general way to express aggregation, which can replace the previous facade pattern of package objects inheriting from classes.
  • Vararg splices now use the form in function arguments and patterns instead of and ,
  • Universal apply methods allow using simple function call syntax instead of expressions. expressions stay around as a fallback for the cases where creator applications cannot be used.

With the exception of early initializers and old-style vararg patterns, all superseded constructs continue to be available in Scala 3.0. The plan is to deprecate and phase them out later.

Value classes (superseded by opaque type aliases) are a special case. There are currently no deprecation plans for value classes, since we might bring them back in a more general form if they are supported natively by the JVM as is planned by project Valhalla.

Restrictions

These constructs are restricted to make the language safer.

  • Implicit Conversions: there is only one way to define implicit conversions instead of many, and potentially surprising implicit conversions require a language import.
  • Given Imports: implicits now require a special form of import, to make the import clearly visible.
  • Type Projection: only classes can be used as prefix of a type projection . Type projection on abstract types is no longer supported since it is unsound.
  • Multiversal Equality: implement an "opt-in" scheme to rule out nonsensical comparisons with and .
  • infix: make method application syntax uniform across code bases.

Unrestricted implicit conversions continue to be available in Scala 3.0, but will be deprecated and removed later. Unrestricted versions of the other constructs in the list above are available only under .

Dropped Constructs

These constructs are proposed to be dropped without a new construct replacing them. The motivation for dropping these constructs is to simplify the language and its implementation.

  • DelayedInit,
  • Existential types,
  • Procedure syntax,
  • Class shadowing,
  • XML literals,
  • Symbol literals,
  • Auto application,
  • Weak conformance,
  • Compound types (replaced by Intersection types),
  • Auto tupling (implemented, but not merged).

The date when these constructs are dropped varies. The current status is:

  • Not implemented at all:
    • DelayedInit, existential types, weak conformance.
  • Supported under :
    • procedure syntax, class shadowing, symbol literals, auto application, auto tupling in a restricted form.
  • Supported in 3.0, to be deprecated and phased out later:

Changes

These constructs have undergone changes to make them more regular and useful.

  • Structural Types: They now allow pluggable implementations, which greatly increases their usefulness. Some usage patterns are restricted compared to the status quo.
  • Name-based pattern matching: The existing undocumented Scala 2 implementation has been codified in a slightly simplified form.
  • Automatic Eta expansion: Eta expansion is now performed universally also in the absence of an expected type. The postfix operator is thus made redundant. It will be deprecated and dropped after Scala 3.0.
  • Implicit Resolution: The implicit resolution rules have been cleaned up to make them more useful and less surprising. Implicit scope is restricted to no longer include package prefixes.

Most aspects of old-style implicit resolution are still available under . The other changes in this list are applied unconditionally.

New Constructs

These are additions to the language that make it more powerful or pleasant to use.

  • Enums provide concise syntax for enumerations and algebraic data types.
  • Parameter untupling avoids having to use for tupled parameter destructuring.
  • Dependent function types generalize dependent methods to dependent function values and types.
  • Polymorphic function types generalize polymorphic methods to polymorphic function values and types. Current status: There is a proposal and a merged prototype implementation, but the implementation has not been finalized (it is notably missing type inference support).
  • Kind polymorphism allows the definition of operators working equally on types and type constructors.
  • annotations make it easier to interoperate with code written in other languages and give more flexibility for avoiding name clashes.

Metaprogramming

The following constructs together aim to put metaprogramming in Scala on a new basis. So far, metaprogramming was achieved by a combination of macros and libraries such as Shapeless that were in turn based on some key macros. Current Scala 2 macro mechanisms are a thin veneer on top the current Scala 2 compiler, which makes them fragile and in many cases impossible to port to Scala 3.

It's worth noting that macros were never included in the Scala 2 language specification and were so far made available only under an flag. This has not prevented their widespread usage.

To enable porting most uses of macros, we are experimenting with the advanced language constructs listed below. These designs are more provisional than the rest of the proposed language constructs for Scala 3.0. There might still be some changes until the final release. Stabilizing the feature set needed for metaprogramming is our first priority.

  • Match Types allow computation on types.
  • Inline provides by itself a straightforward implementation of some simple macros and is at the same time an essential building block for the implementation of complex macros.
  • Quotes and Splices provide a principled way to express macros and staging with a unified set of abstractions.
  • Type class derivation provides an in-language implementation of the macro in Shapeless and other foundational libraries. The new implementation is more robust, efficient and easier to use than the macro.
  • By-name context parameters provide a more robust in-language implementation of the macro in Shapeless.

See Also

A classification of proposed language features is an expanded version of this page that adds the status (i.e. relative importance to be a part of Scala 3, and relative urgency when to decide this) and expected migration cost of each language construct.

Sours: https://dotty.epfl.ch/docs/reference/overview.html
What's new in Scala 3: all the \

Work in Progress

We are still in the process of writing the documentation for Scala 3. You can help us to improve the documentation.

Are you searching for the Scala 2 documentation?

The exciting new version of Scala 3 brings many improvements and new features. Here we provide you with a quick overview of the most important changes. If you want to dig deeper, there are a few references at your disposal:

  • The Scala 3 Book targets developers new to the Scala language.
  • The Syntax Summary provides you with a formal description of the new syntax.
  • The Language Reference gives a detailed description of the changes from Scala 2 to Scala 3.
  • The Migration Guide provides you with all of the information necessary to move from Scala 2 to Scala 3.
  • The Contribution Guide dives deeper into the compiler, including a guide to fix issues.

What’s new in Scala 3

Scala 3 is a complete overhaul of the Scala language. At its core, many aspects of the type-system have been changed to be more principled. While this also brings exciting new features along (like union types), first and foremost, it means that the type-system gets (even) less in your way and for instance type-inference and overload resolution are much improved.

New & Shiny: The Syntax

Besides many (minor) cleanups, the Scala 3 syntax offers the following improvements:

Opinionated: Contextual Abstractions

One underlying core concept of Scala was (and still is to some degree) to provide users with a small set of powerful features that can be combined to great (and sometimes even unforeseen) expressivity. For example, the feature of implicits has been used to model contextual abstraction, to express type-level computation, model type-classes, perform implicit coercions, encode extension methods, and many more. Learning from these use cases, Scala 3 takes a slightly different approach and focuses on intent rather than mechanism. Instead of offering one very powerful feature, Scala 3 offers multiple tailored language features, allowing programmers to directly express their intent:

  • Abstracting over contextual information. Using clauses allow programmers to abstract over information that is available in the calling context and should be passed implicitly. As an improvement over Scala 2 implicits, using clauses can be specified by type, freeing function signatures from term variable names that are never explicitly referred to.

  • Providing Type-class instances. Given instances allow programmers to define the canonical value of a certain type. This makes programming with type-classes more straightforward without leaking implementation details.

  • Retroactively extending classes. In Scala 2, extension methods had to be encoded using implicit conversions or implicit classes. In contrast, in Scala 3 extension methods are now directly built into the language, leading to better error messages and improved type inference.

  • Viewing one type as another. Implicit conversions have been redesigned from the ground up as instances of a type-class .

  • Higher-order contextual abstractions. The all-new feature of context functions makes contextual abstractions a first-class citizen. They are an important tool for library authors and allow to express concise domain specific languages.

  • Actionable feedback from the compiler. In case an implicit parameter cannot be resolved by the compiler, it now provides import suggestions that may fix the problem.

Say What You Mean: Type System Improvements

Besides greatly improved type inference, the Scala 3 type system also offers many new features, giving you powerful tools to statically express invariants in the types:

  • Enumerations. Enums have been redesigned to blend well with case classes and form the new standard to express algebraic data types.

  • Opaque Types. Hide implementation details behind opaque type aliases without paying for it in performance! Opaque types supersede value classes and allow you to set up an abstraction barrier without causing additional boxing overhead.

  • Intersection and union types. Basing the type system on new foundations led to the introduction of new type system features: instances of intersection types, like , are instances of both and of . Instances of union types, like , are instances of either or . Both constructs allow programmers to flexibly express type constraints outside of the inheritance hierarchy.

  • Dependent function types. Scala 2 already allowed return types to depend on (value) arguments. In Scala 3 it is now possible to abstract over this pattern and express dependent function types. In the type the result type depends on the argument!

  • Polymorphic function types. Like with dependent function types, Scala 2 supported methods that allow type parameters, but did not allow programmers to abstract over those methods. In Scala 3, polymorphic function types like can abstract over functions that take type arguments in addition to their value arguments.

  • Type lambdas. What needed to be expressed using a compiler plugin in Scala 2 is now a first-class feature in Scala 3: Type lambdas are type level functions that can be passed as (higher-kinded) type arguments without requiring an auxiliary type definition.

  • Match types. Instead of encoding type-level computation using implicit resolution, Scala 3 offers direct support for matching on types. Integrating type-level computation into the type checker enables improved error messages and removes the need for complicated encodings.

Re-envisioned: Object-Oriented Programming

Scala has always been at the frontier between functional programming and object-oriented programming – and Scala 3 pushes boundaries in both directions! The above-mentioned type system changes and the redesign of contextual abstractions make functional programming easier than before. At the same time, the following novel features enable well-structured object-oriented designs and support best practices.

  • Pass it on. Traits move closer to classes and now can also take parameters, making them even more powerful as a tool for modular software decomposition.
  • Plan for extension. Extending classes that are not intended for extension is a long-standing problem in object-oriented design. To address this issue, open classes require library designers to explicitly mark classes as open.
  • Hide implementation details. Utility traits that implement behavior sometimes should not be part of inferred types. In Scala 3, those traits can be marked as transparent hiding the inheritance from the user (in inferred types).
  • Composition over inheritance. This phrase is often cited, but tedious to implement. Not so with Scala 3’s export clauses: symmetric to imports, export clauses allow the user to define aliases for selected members of an object.
  • No more NPEs. Scala 3 is safer than ever: explicit null moves out of the type hierarchy, helping you to catch errors statically; additional checks for safe initialization detect access to uninitialized objects.

Batteries Included: Metaprogramming

While macros in Scala 2 were an experimental feature only, Scala 3 comes with a powerful arsenal of tools for metaprogramming. The macro tutorial contains detailed information on the different facilities. In particular, Scala 3 offers the following features for metaprogramming:

  • Inline. As the basic starting point, the inline feature allows values and methods to be reduced at compile time. This simple feature already covers many use-cases and at the same time provides the entry point for more advanced features.
  • Compile-time operations. The package contains additional functionality that can be used to implement inline methods.
  • Quoted code blocks. Scala 3 adds the new feature of quasi-quotation for code, providing a convenient high-level interface to construct and analyse code. Constructing code for adding one and one is as easy as .
  • Reflection API. For more advanced use cases quotes.reflect provides more detailed control to inspect and generate program trees.

If you want to learn more about metaprogramming in Scala 3, we invite you to take our tutorial.

Contributors to this page:

Sours: https://docs.scala-lang.org/scala3/new-in-scala3.html

3 features scala

Scala 3 brings major features and improvements in the new upgrade

The overhaul of the Scala language - - includes several aspects of the type-system that brings out the new feature set like union types. It offers features like overload resolution and type-interference to improve the performance of the developers. There are several new aspects included in Syntax 3 that are listed below:

1. The Syntax
The major syntax that is included in the Scala 3 are:

  • The new keyword is optional
  • The new quiet syntax for control structures
  • Change of type-level wildcards
  • Optional braces for the indentation sensitive style and distraction-free support

2. Type System Improvements
Scala 3 works on the type inference improvements that offers powerful tools to statistically express invariants. This includes:

  • Opaque types
  • Enumerations
  • Intersection and union types
  • Polymorphic function types
  • Dependent function types
  • Match types
  • Type lambdas

3. Contextual Abstractions
Scala 3 concept can work on the powerful features that are well-combined with the expressivity and implicit features to perform the implicit coercions, model type-class, encode extension methods, type-level computations, etc. This includes:

  • Providing type-class instances
  • Abstracting over contextual information
  • Viewing one type as another
  • Retroactively extending classes
  • Actionable feedback from the compiler
  • Higher-order contextual abstractions

4. Metaprogramming
Metaprogramming is an experimental feature that comes out as the powerful arsenal of tools facilitating different information. This includes:

  • Compile-time operations
  • Inline
  • Reflection API
  • Quoted code blocks

5. Object-Oriented Programming
Object-oriented concepts are the core of the programming languages along with functional programming. It includes the type of system changes and the contextual abstractions redesigning that offers ease in coding. The features include:
  • Plan for extension
  • Pass in on
  • Composition over inheritance
  • No more NPEs
  • Hide implementation details
Sours: https://content.techgig.com/scala-3-brings-major-features-and-improvements-in-the-new-upgrade/articleshow/82709558.cms
Scala 3. History, Features Review and more by Vladyslav Kopaniev

Scala 3 ushers in ‘complete overhaul’ of the language

The latest upgrade of the popular functional language for JVM and JavaScript runtimes features a new type system, new language features, and scads of syntax improvements.

Scala 3 ushers in ‘complete overhaul’ of the language

Scala 3, the latest version of the object-oriented, functional language with JVM and JavaScript runtimes, is now available as a production release. The upgrade, described by the project as a “complete overhaul,” features a new type system and syntax improvements.

The production release of Scala 3 was introduced May 14, following a release candidate stage that began on February 17. Among the improvements noted in the release is a new “quiet” syntax for control structures such as if, while, and for.

[ Also on InfoWorld: JDK 17: The new features in Java 17 ]

Scala has both JVM and JavaScript runtimes and is positioned for use in building high-performance systems with access to ecosystems of libraries. Instructions for downloading Scala 3 can be found here.

Other syntax improvements in Scala 3:

  • Optional braces that support a distraction-free, indentation-sensitive style of programming.
  • The keyword is now optional.
  • Type-level wildcards have been changed from to .
  • Implicits and their syntax have been heavily revised.

New language features in Scala 3:

  • In an improvement over Scala 2 implicits, using clauses can be specified by type, freeing function signatures from term variable names that are never explicitly referred to.
  • Given instances allow programmers to determine the canonical value of a certain type, making programming with type-classes more straightforward, without leaking implementation details.
  • Extension methods are now directly built into the language, for better error messages and improved type inference.
  • Implicit conversions have been redesigned as instances of a type-class .
  • A context functions feature makes contextual abstractions a first-class citizen. These serve as a tool for library authors to express concise domain-specific languages.
  • If an implicit parameter cannot be resolved by the compiler, import suggestions are provided that may fix the problem.

Type system improvements in Scala 3:

  • Enums, or enumerations, have been redesigned to blend well with case classes and form the new standard to express algebraic data types.
  • Opaque type aliases enable developers to hide implementation details without taking a performance hit.
  • Intersection and union types enable expression of type constraints outside the inheritance hierarchy.
  • Polymorphic function types can abstract over functions that take type arguments in addition to their value arguments.
  • Type lambdas are type-level functions that can be passed as type arguments without needing an auxiliary type definition.
  • Rather than encoding type-level computation using implicit resolution, Scala 3 supports matching on types.

Object-oriented programming features in Scala 3:

  • Traits move closer to classes and now can take parameters, thus making them more powerful as a tool for modular software decomposition.
  • Open classes require library designers to mark classes as open.
  • Utility traits that implement behavior sometimes ought not be part of inferred types. With Scala 3, those traits can be marked as transparent, hiding the inheritance from the user.
  • Explicit null moves null out of the type hierarchy, for catching errors statically. Additional checks for safe initialization find access to unitialized objects.

Scala 3 also offers tools for metaprogramming, including compile-time operations, quoted code blocks, and an inline feature that allows values and methods to be reduced at compile time.

Paul Krill is an editor at large at InfoWorld, whose coverage focuses on application development.

Copyright © 2021 IDG Communications, Inc.

How to choose a low-code development platform

InfoWorld
IDG Communications

Copyright © 2021 IDG Communications, Inc.

Explore the IDG Network descend

Sours: https://www.infoworld.com/article/3608574/scala-3-moves-to-release-candidate-stage.html

You will also be interested:

I decided that he wanted to please the guest and agreed. In the end, we turned out to be at Michael's house, where he opened his trousers right in the hallway, put me on his knees and made him soak. Off his unwashed waste. When I finished, I got 50 bucks and put it out the door. I felt like a real whore.



1386 1387 1388 1389 1390