SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Scala 3 Is Coming
By Martin Odersky
July 11th, 2019
Roadmap
June 2019 All features fleshed out, with
implementations in Dotty 0.16+
Fall 2019 Feature freeze, Scala 3.0 M1
stabilization
complete SIP process
write spec, user docs
migrate open-source ecosystem
flesh out tests, community build
compatibility and migration tools
Fall 2020 Scala 3.0 final
Scala 2.13
Scala 2.14
A Tour of Scala 3
What Changes?
Docs for all changes and new features at
https://dotty.epfl.ch/docs/reference/overview.html
?
Best of Scala 3
What are Scala-3’s Nicest Features?
• For beginners
• For everyday coding
• For experts
I’ll give my personal ranking
of the top 3 of each category.
I also did a Twitter survey and will report on that.
?
?
Nicest Features for Beginners?
• At that level, most of the language stays the same
• But there are nevertheless a few improvements worth
mentioning …
?
#3: Drop New
• new can be omitted from almost all instance creations.
• Only needed to disambiguate in an apply method.
• No need to define a case class anymore just to get nice
constructor calls.
class StringBuilder(s: String) {
def this() = this("")
}
StringBuilder("abc") // same as new StringBuilder("abc") StringBuilder() // same as new
StringBuilder()
#2: Toplevel Definitions
All kinds of definitions can be written on the toplevel.
Package objects are no longer needed, will be phased out.
package p
type Labelled[T] = (String, T)
val a: Labelled[Int] = ("count", 1)
def b = a._2
def hello(name: String) =
println(i"hello, $name)
#1 Enums
enum Color {
case Red, Green, Blue
}
Simplest way to define new types with a finite number of values or
constructors.
#1 Enums
can have parameters
can define fields and methods
can interop with Java
enum Planet(mass: Double, radius: Double)
extends java.lang.Enum {
private final val G = 6.67300E-11
def surfaceGravity = G * mass / (radius * radius)
case MERCURY extends Planet(3.303e+23, 2.4397e6)
case VENUS extends Planet(4.869e+24, 6.0518e6)
case EARTH extends Planet(5.976e+24, 6.37814e6)
case MARS extends Planet(6.421e+23, 3.3972e6)
...
}
#1 Enums
can have type parameters, making them algebraic data types (ADTs)
enum Option[+T] {
case Some(x: T)
case None
}
#1 Enums
compile to sealed hierarchies of case classes and singletons.
sealed abstract class Option[+T]
object Option {
case class Some[+T](x: T) extends Option[T]
val None = new Option[Nothing] { ... }
}
#1 Enums
can be GADTs (generalized ADTs).
 cases can extend the base type with different type arguments.
enum Tree[T] {
case True extends Tree[Boolean]
case False extends Tree[Boolean]
case IsZero(n: Tree[Int]) extends Tree[Boolean]
case Zero extends Tree[Int]
case Succ(n: Tree[Int]) extends Tree[Int]
case If(cond: Tree[Boolean],
thenp: Tree[T],
elsep: Tree[T]) extends Tree[T]
}
The public vote:
Why Enums?
• Lots of use cases, and they are becoming more common.
• Avoids boring, repetitive boilerplate.
• Can grow from very simple to very powerful.
Nicest Features for Everyday Coding?
• There are lots of candidates.
• Hard to come up with a shortlist.
?
#3 Union Types
Provide ad-hoc combinations of types
Subsetting = Subtyping
No boxing overhead
case class UserName(name: String)
case class Password(hash: Hash)
def help(id: UserName | Password) = {
val user = id match {
case UserName(name) => lookupName(name)
case Password(hash) => lookupPassword(hash)
}
...
}
#3 Union Types
Work also with singleton types
Great for JS interop
type Command = ”Click" | ”Drag" | ”KeyPressed"
def handleEvent(kind: Command) = kind match {
case “Click" => MouseClick()
case ”Drag" => MoveTo()
case ”KeyPressed" => KeyPressed()
}
#2 Extension Methods
Replace implicit classes
Make it easier to add methods to existing classes.
object StringOps {
def (s: String) * (x: Int): String =
if (x <= 0) “” else s * (x - 1) ++ s
}
import StringOps._
"hello" * 3
#1 Givens
Replace “implicit” as a modifier
Express intent instead of mechanism
trait Ord[T] {
def (x: T) compareTo (y: T): Int
def (x: T) < (y: T) = x.compareTo(y) < 0
}
given IntOrd as Ord[Int] {
def (x: Int) compareTo (y: Int) =
if (x < y) -1 else if (x > y) +1 else 0
}
def maximum[T](xs: List[T]) given Ord[T] =
xs.reduce((x, y) => if (x < y) y else x)
New Design Principles
• Core concept: term inference.
• Given a type, produce a canonical term of that type
“Trade types for terms”
• Instead of adding implicit as a modifier to many different
constructs, changing the meaning of each in slightly
different ways, have a single construct to introduce a
designated term that can be inferred for a type.
• We call these terms “given instances” or just “givens”.
Typeclasses
Givens work out of the box with extension methods,
provide a nice syntax for typeclasses
trait SemiGroup[T] {
def (x: T) combine (y: T): T
}
trait Monoid[T] extends SemiGroup[T] {
def unit: T
}
given as Monoid[String] {
def (x: String) combine (y: String) = x.concat(y)
def unit = ""
}
def sum[T: Monoid](xs: List[T]): T =
xs.foldLeft( the[Monoid[T]].unit )(_.combine(_))
Implicit Conversions
implicit def intToStr(str: String): Token =
new Keyword(str)
Givens tame implicit conversions
What’s wrong with this?
It’s too easy to write compared to how dangerous it is.
Implicit as a modifier will go away, and with it this kind of conversion.
Conversion Instances
The only way to express implicit conversions is as a given instance
of a standard Conversion class:
given as Conversion[String, Token] {
def apply(str: String): Token = new KeyWord(str)
}
Or, using an alias:
given as Conversion[String, Token] =
new KeyWord(_)
The public vote:
Why “Given”?
Implicits are Scala’s most distinguished feature.
But they are also the most controversial one.
Given instances are a simpler and safer alternative. They
• emphasize intent over mechanism
• make idea of term inference more accessible
• discourage abuses
Why “Given”?
Many improvements over current implicits, including:
• names don’t matter
• nesting is significant  local coherence is easy
• no shadowing problems
• restricted implicit scope avoids surprises
• more robust prioritization
• no accidental conversions
• better error messages
 More details in my Typelevel Lausanne keynote
Migration
• Current implicits are still supported in Scala 3.0
• Will probably be deprecated from Scala 3.1 on.
• Special provisions are made for cross compilation:
- given arguments also work for old style implicits
- given imports also import old style implicits
• This allows to migrate user code before libraries are moved over.
The Hardest Thing…
… was naming them!
The design of delegates has been solid for 6 months,
but how do we call these terms that get inferred for types?
We went through a long list of names:
In the end, it will not matter, just need a noun that’s easy to remember.
witness evidence
instance
impl
repr
assume
representative
delegate
implied
implicit
Nicest Features for Experts?
• Since Scala 3 puts Meta Programming on a new basis, there is
lots to choose from.
• Difficult to pick a winner.
?
#3 Match Types
• Match types can be recursive.
• More straightforward than using implicits (c.f. HLists).
• Work in type checking is still in progress
enum Tuple {
case Empty
case Pair[Hd, Tl]
}
import Tuple._
type Concat[+Xs <: Tuple, +Ys <: Tuple] <: Tuple =
Xs match {
case Empty => Ys
case Pair[x, xs] => Pair[x, Concat[xs, Ys]]
}
#2 Typeclass Derivation
enum Tree[T] derives Eql, Ordering, Pickling {
case Branch(left: Tree[T], right: Tree[T])
case Leaf(elem: T)
}
given [T: Eql] as Eql[Tree[T]] = Eql.derived
given [T: Ordering] as Ordering[Tree[T]] = Ordering.derived
given [T: Pickling] as Pickling[Tree[T]] = Pickling.derived
this generates:
where typeclasses define “derived” methods.
 ScalaDays Talk by Miles Sabin
#2 Typeclass Derivation
“derived” methods use match types, inline and macros to do their work
object Eq {
inline def derived[T] given (mirror: Mirror.Of[T]): Eq[T] =
new Eq[T] {
def eql(x: T, y: T): Boolean =
inline mirror match {
case m: Mirror.SumOf[T] =>
val ord = m.ordinal(x)
ord == m.ordinal(y) && eqlCases[m.ElemTypes](0)(x, y, ord)
case m: Mirror.ProductOf[T] =>
eqlElems[m.ElemTypes](0)(x, y)
}
}
 ScalaDays Talk by Nicolas Stucki
#1 Functions Everywhere
Scala distinguishes methods from functions.
Scala 3 lifts three fundamental capabilities from one to the other.
Function types can be:
• dependent:
• polymorphic:
• implicit:
trait Graph { type Node; type Edge }
type NodeExtractor = (g: Graph) => g.Node
type PolyIdentity = [T] => T => T
type Executable[T] = given ExecutionContext => T
The public vote:
(“functions everywhere” was a write-in from Miles)
Synergies
object PostConditions {
opaque type Wrap[T] = T
def result[T] given (r: Wrap[T]): T = r
def (x: T) ensuring [T] (cond: given Wrap[T] => Boolean): T =
assert(cond given x)
}
import PostConditions.{ensuring, result}
List(1, 2, 3)
.sum
.ensuring(result == 6)
Is Scala 3 a New Language?
Is Scala 3 a New Language?
Yes!
• Many language changes, including feature removals.
• New constructs improve user experience and on-boarding.
• Books will have to be rewritten.
Is Scala 3 a New Language?
No!
• It’s still Scala.
• All core constructs remain in place.
• Large & practical common subset between Scala 2 and Scala 3.
• Programs can cross-build
 Dotty compiler, ScalaTest.
Is Scala 3 a New Language?
It’s a Process
• Scala 3.0 keeps most constructs of 2.13, alongside the new ones.
• Some constructs will be deprecated and phased out in the 3.x
release train.
• This requires some temporary duplication.
• End result: a more compact and regular language.
Replacements
Exports + toplevel defs for Package objects
Givens for Implicit defs, vals, objects,
conversions
Extension methods for Implicit classes
Inline + staging + for Current macros
match types
Why So Many New Features At Once?
Scala 3 is when the
books will be rewritten.
Need to get it in now if
• it affects foundations,
• it simplifies life,
especially for
learners,
• it replaces existing
features.
Why So Many New Features At Once?
Hence, prioritize
- Foundations
- Simplifications
(for developers)
- Restrictions
over added power and
expressiveness
How to Get There?
• Source compatibility for a large common subset.
• Rewrite tools can handle much of the rest
• Situation better than for Python 2 vs 3 because of static typing &
binary compatibility.
 Talk by Lukas Rytz, Wed 16.45
Binary Compatibility
today:
Dotty can link with
Scala-2.12 class files.
Scala 2 module
Dotty module
Binary Compatibility
today:
Dotty can link with
Scala-2.12 class files.
Scala 2 module
Dotty module
in the works:
Two way compatibility
using Tasty as common
intermediate format.
Scala 2 module
Scala 3 module
Tasty At The Core
Tasty
.scala (2.x)
.scala (3.x)
.class (Java 8)
.js
.class (Java 11)
.out
macros
analyzers
optimizers
IDE
LSP
 Talk by Gullaume Martres, Wed 10.15
Binary Compatibility For Scala 3
• The plan is to keep the Tasty format binary compatible
over the whole 3.x series.
• Compile-from Tasty then allows code to migrate without
the current problems of binary compatibility.
Try it out: dotty.epfl.ch
Thank You

Weitere ähnliche Inhalte

Was ist angesagt?

Querying XML: XPath and XQuery
Querying XML: XPath and XQueryQuerying XML: XPath and XQuery
Querying XML: XPath and XQuery
Katrien Verbert
 

Was ist angesagt? (20)

Streaming SQL with Apache Calcite
Streaming SQL with Apache CalciteStreaming SQL with Apache Calcite
Streaming SQL with Apache Calcite
 
Pandas csv
Pandas csvPandas csv
Pandas csv
 
Map/Reduce intro
Map/Reduce introMap/Reduce intro
Map/Reduce intro
 
Pandas
PandasPandas
Pandas
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
Python Collections Tutorial | Edureka
Python Collections Tutorial | EdurekaPython Collections Tutorial | Edureka
Python Collections Tutorial | Edureka
 
MySQL Optimizer Cost Model
MySQL Optimizer Cost ModelMySQL Optimizer Cost Model
MySQL Optimizer Cost Model
 
Introducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data ScienceIntroducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data Science
 
Pandas Dataframe reading data Kirti final.pptx
Pandas Dataframe reading data  Kirti final.pptxPandas Dataframe reading data  Kirti final.pptx
Pandas Dataframe reading data Kirti final.pptx
 
Data visualization with R
Data visualization with RData visualization with R
Data visualization with R
 
What No One Tells You About Writing a Streaming App: Spark Summit East talk b...
What No One Tells You About Writing a Streaming App: Spark Summit East talk b...What No One Tells You About Writing a Streaming App: Spark Summit East talk b...
What No One Tells You About Writing a Streaming App: Spark Summit East talk b...
 
Apache Spark Introduction
Apache Spark IntroductionApache Spark Introduction
Apache Spark Introduction
 
Querying XML: XPath and XQuery
Querying XML: XPath and XQueryQuerying XML: XPath and XQuery
Querying XML: XPath and XQuery
 
Big data processing using Hadoop with Cloudera Quickstart
Big data processing using Hadoop with Cloudera QuickstartBig data processing using Hadoop with Cloudera Quickstart
Big data processing using Hadoop with Cloudera Quickstart
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
 
pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data Analysis
 
plsql.ppt
plsql.pptplsql.ppt
plsql.ppt
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 

Ähnlich wie Scala 3 Is Coming: Martin Odersky Shares What To Know

Stack squeues lists
Stack squeues listsStack squeues lists
Stack squeues lists
James Wong
 
Stacksqueueslists
StacksqueueslistsStacksqueueslists
Stacksqueueslists
Fraboni Ec
 

Ähnlich wie Scala 3 Is Coming: Martin Odersky Shares What To Know (20)

C# programming
C# programming C# programming
C# programming
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Erlang session1
Erlang session1Erlang session1
Erlang session1
 
Templates presentation
Templates presentationTemplates presentation
Templates presentation
 
Python basics
Python basicsPython basics
Python basics
 
Templates2
Templates2Templates2
Templates2
 
Scala and Deep Learning
Scala and Deep LearningScala and Deep Learning
Scala and Deep Learning
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
 
Testing for share
Testing for share Testing for share
Testing for share
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
From DOT to Dotty
From DOT to DottyFrom DOT to Dotty
From DOT to Dotty
 
presentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptxpresentation on important DAG,TRIE,Hashing.pptx
presentation on important DAG,TRIE,Hashing.pptx
 
Lec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questionsLec2_cont.pptx galgotias University questions
Lec2_cont.pptx galgotias University questions
 
Stack squeues lists
Stack squeues listsStack squeues lists
Stack squeues lists
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues lists
 
Stacksqueueslists
StacksqueueslistsStacksqueueslists
Stacksqueueslists
 
Stacks queues lists
Stacks queues listsStacks queues lists
Stacks queues lists
 

Mehr von Lightbend

Mehr von Lightbend (20)

IoT 'Megaservices' - High Throughput Microservices with Akka
IoT 'Megaservices' - High Throughput Microservices with AkkaIoT 'Megaservices' - High Throughput Microservices with Akka
IoT 'Megaservices' - High Throughput Microservices with Akka
 
How Akka Cluster Works: Actors Living in a Cluster
How Akka Cluster Works: Actors Living in a ClusterHow Akka Cluster Works: Actors Living in a Cluster
How Akka Cluster Works: Actors Living in a Cluster
 
The Reactive Principles: Eight Tenets For Building Cloud Native Applications
The Reactive Principles: Eight Tenets For Building Cloud Native ApplicationsThe Reactive Principles: Eight Tenets For Building Cloud Native Applications
The Reactive Principles: Eight Tenets For Building Cloud Native Applications
 
Putting the 'I' in IoT - Building Digital Twins with Akka Microservices
Putting the 'I' in IoT - Building Digital Twins with Akka MicroservicesPutting the 'I' in IoT - Building Digital Twins with Akka Microservices
Putting the 'I' in IoT - Building Digital Twins with Akka Microservices
 
Akka at Enterprise Scale: Performance Tuning Distributed Applications
Akka at Enterprise Scale: Performance Tuning Distributed ApplicationsAkka at Enterprise Scale: Performance Tuning Distributed Applications
Akka at Enterprise Scale: Performance Tuning Distributed Applications
 
Digital Transformation with Kubernetes, Containers, and Microservices
Digital Transformation with Kubernetes, Containers, and MicroservicesDigital Transformation with Kubernetes, Containers, and Microservices
Digital Transformation with Kubernetes, Containers, and Microservices
 
Detecting Real-Time Financial Fraud with Cloudflow on Kubernetes
Detecting Real-Time Financial Fraud with Cloudflow on KubernetesDetecting Real-Time Financial Fraud with Cloudflow on Kubernetes
Detecting Real-Time Financial Fraud with Cloudflow on Kubernetes
 
Cloudstate - Towards Stateful Serverless
Cloudstate - Towards Stateful ServerlessCloudstate - Towards Stateful Serverless
Cloudstate - Towards Stateful Serverless
 
Digital Transformation from Monoliths to Microservices to Serverless and Beyond
Digital Transformation from Monoliths to Microservices to Serverless and BeyondDigital Transformation from Monoliths to Microservices to Serverless and Beyond
Digital Transformation from Monoliths to Microservices to Serverless and Beyond
 
Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6
Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6
Akka Anti-Patterns, Goodbye: Six Features of Akka 2.6
 
Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...
Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...
Lessons From HPE: From Batch To Streaming For 20 Billion Sensors With Lightbe...
 
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
How to build streaming data pipelines with Akka Streams, Flink, and Spark usi...
 
Microservices, Kubernetes, and Application Modernization Done Right
Microservices, Kubernetes, and Application Modernization Done RightMicroservices, Kubernetes, and Application Modernization Done Right
Microservices, Kubernetes, and Application Modernization Done Right
 
Full Stack Reactive In Practice
Full Stack Reactive In PracticeFull Stack Reactive In Practice
Full Stack Reactive In Practice
 
Akka and Kubernetes: A Symbiotic Love Story
Akka and Kubernetes: A Symbiotic Love StoryAkka and Kubernetes: A Symbiotic Love Story
Akka and Kubernetes: A Symbiotic Love Story
 
Migrating From Java EE To Cloud-Native Reactive Systems
Migrating From Java EE To Cloud-Native Reactive SystemsMigrating From Java EE To Cloud-Native Reactive Systems
Migrating From Java EE To Cloud-Native Reactive Systems
 
Running Kafka On Kubernetes With Strimzi For Real-Time Streaming Applications
Running Kafka On Kubernetes With Strimzi For Real-Time Streaming ApplicationsRunning Kafka On Kubernetes With Strimzi For Real-Time Streaming Applications
Running Kafka On Kubernetes With Strimzi For Real-Time Streaming Applications
 
Designing Events-First Microservices For A Cloud Native World
Designing Events-First Microservices For A Cloud Native WorldDesigning Events-First Microservices For A Cloud Native World
Designing Events-First Microservices For A Cloud Native World
 
Scala Security: Eliminate 200+ Code-Level Threats With Fortify SCA For Scala
Scala Security: Eliminate 200+ Code-Level Threats With Fortify SCA For ScalaScala Security: Eliminate 200+ Code-Level Threats With Fortify SCA For Scala
Scala Security: Eliminate 200+ Code-Level Threats With Fortify SCA For Scala
 
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On KubernetesHow To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
How To Build, Integrate, and Deploy Real-Time Streaming Pipelines On Kubernetes
 

Kürzlich hochgeladen

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Kürzlich hochgeladen (20)

%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 

Scala 3 Is Coming: Martin Odersky Shares What To Know

  • 1. Scala 3 Is Coming By Martin Odersky July 11th, 2019
  • 2. Roadmap June 2019 All features fleshed out, with implementations in Dotty 0.16+ Fall 2019 Feature freeze, Scala 3.0 M1 stabilization complete SIP process write spec, user docs migrate open-source ecosystem flesh out tests, community build compatibility and migration tools Fall 2020 Scala 3.0 final Scala 2.13 Scala 2.14
  • 3. A Tour of Scala 3
  • 4. What Changes? Docs for all changes and new features at https://dotty.epfl.ch/docs/reference/overview.html
  • 5. ? Best of Scala 3 What are Scala-3’s Nicest Features? • For beginners • For everyday coding • For experts I’ll give my personal ranking of the top 3 of each category. I also did a Twitter survey and will report on that. ? ?
  • 6. Nicest Features for Beginners? • At that level, most of the language stays the same • But there are nevertheless a few improvements worth mentioning … ?
  • 7. #3: Drop New • new can be omitted from almost all instance creations. • Only needed to disambiguate in an apply method. • No need to define a case class anymore just to get nice constructor calls. class StringBuilder(s: String) { def this() = this("") } StringBuilder("abc") // same as new StringBuilder("abc") StringBuilder() // same as new StringBuilder()
  • 8. #2: Toplevel Definitions All kinds of definitions can be written on the toplevel. Package objects are no longer needed, will be phased out. package p type Labelled[T] = (String, T) val a: Labelled[Int] = ("count", 1) def b = a._2 def hello(name: String) = println(i"hello, $name)
  • 9. #1 Enums enum Color { case Red, Green, Blue } Simplest way to define new types with a finite number of values or constructors.
  • 10. #1 Enums can have parameters can define fields and methods can interop with Java enum Planet(mass: Double, radius: Double) extends java.lang.Enum { private final val G = 6.67300E-11 def surfaceGravity = G * mass / (radius * radius) case MERCURY extends Planet(3.303e+23, 2.4397e6) case VENUS extends Planet(4.869e+24, 6.0518e6) case EARTH extends Planet(5.976e+24, 6.37814e6) case MARS extends Planet(6.421e+23, 3.3972e6) ... }
  • 11. #1 Enums can have type parameters, making them algebraic data types (ADTs) enum Option[+T] { case Some(x: T) case None }
  • 12. #1 Enums compile to sealed hierarchies of case classes and singletons. sealed abstract class Option[+T] object Option { case class Some[+T](x: T) extends Option[T] val None = new Option[Nothing] { ... } }
  • 13. #1 Enums can be GADTs (generalized ADTs).  cases can extend the base type with different type arguments. enum Tree[T] { case True extends Tree[Boolean] case False extends Tree[Boolean] case IsZero(n: Tree[Int]) extends Tree[Boolean] case Zero extends Tree[Int] case Succ(n: Tree[Int]) extends Tree[Int] case If(cond: Tree[Boolean], thenp: Tree[T], elsep: Tree[T]) extends Tree[T] }
  • 15. Why Enums? • Lots of use cases, and they are becoming more common. • Avoids boring, repetitive boilerplate. • Can grow from very simple to very powerful.
  • 16. Nicest Features for Everyday Coding? • There are lots of candidates. • Hard to come up with a shortlist. ?
  • 17. #3 Union Types Provide ad-hoc combinations of types Subsetting = Subtyping No boxing overhead case class UserName(name: String) case class Password(hash: Hash) def help(id: UserName | Password) = { val user = id match { case UserName(name) => lookupName(name) case Password(hash) => lookupPassword(hash) } ... }
  • 18. #3 Union Types Work also with singleton types Great for JS interop type Command = ”Click" | ”Drag" | ”KeyPressed" def handleEvent(kind: Command) = kind match { case “Click" => MouseClick() case ”Drag" => MoveTo() case ”KeyPressed" => KeyPressed() }
  • 19. #2 Extension Methods Replace implicit classes Make it easier to add methods to existing classes. object StringOps { def (s: String) * (x: Int): String = if (x <= 0) “” else s * (x - 1) ++ s } import StringOps._ "hello" * 3
  • 20. #1 Givens Replace “implicit” as a modifier Express intent instead of mechanism trait Ord[T] { def (x: T) compareTo (y: T): Int def (x: T) < (y: T) = x.compareTo(y) < 0 } given IntOrd as Ord[Int] { def (x: Int) compareTo (y: Int) = if (x < y) -1 else if (x > y) +1 else 0 } def maximum[T](xs: List[T]) given Ord[T] = xs.reduce((x, y) => if (x < y) y else x)
  • 21. New Design Principles • Core concept: term inference. • Given a type, produce a canonical term of that type “Trade types for terms” • Instead of adding implicit as a modifier to many different constructs, changing the meaning of each in slightly different ways, have a single construct to introduce a designated term that can be inferred for a type. • We call these terms “given instances” or just “givens”.
  • 22. Typeclasses Givens work out of the box with extension methods, provide a nice syntax for typeclasses trait SemiGroup[T] { def (x: T) combine (y: T): T } trait Monoid[T] extends SemiGroup[T] { def unit: T } given as Monoid[String] { def (x: String) combine (y: String) = x.concat(y) def unit = "" } def sum[T: Monoid](xs: List[T]): T = xs.foldLeft( the[Monoid[T]].unit )(_.combine(_))
  • 23. Implicit Conversions implicit def intToStr(str: String): Token = new Keyword(str) Givens tame implicit conversions What’s wrong with this? It’s too easy to write compared to how dangerous it is. Implicit as a modifier will go away, and with it this kind of conversion.
  • 24. Conversion Instances The only way to express implicit conversions is as a given instance of a standard Conversion class: given as Conversion[String, Token] { def apply(str: String): Token = new KeyWord(str) } Or, using an alias: given as Conversion[String, Token] = new KeyWord(_)
  • 26. Why “Given”? Implicits are Scala’s most distinguished feature. But they are also the most controversial one. Given instances are a simpler and safer alternative. They • emphasize intent over mechanism • make idea of term inference more accessible • discourage abuses
  • 27. Why “Given”? Many improvements over current implicits, including: • names don’t matter • nesting is significant  local coherence is easy • no shadowing problems • restricted implicit scope avoids surprises • more robust prioritization • no accidental conversions • better error messages  More details in my Typelevel Lausanne keynote
  • 28. Migration • Current implicits are still supported in Scala 3.0 • Will probably be deprecated from Scala 3.1 on. • Special provisions are made for cross compilation: - given arguments also work for old style implicits - given imports also import old style implicits • This allows to migrate user code before libraries are moved over.
  • 29. The Hardest Thing… … was naming them! The design of delegates has been solid for 6 months, but how do we call these terms that get inferred for types? We went through a long list of names: In the end, it will not matter, just need a noun that’s easy to remember. witness evidence instance impl repr assume representative delegate implied implicit
  • 30. Nicest Features for Experts? • Since Scala 3 puts Meta Programming on a new basis, there is lots to choose from. • Difficult to pick a winner. ?
  • 31. #3 Match Types • Match types can be recursive. • More straightforward than using implicits (c.f. HLists). • Work in type checking is still in progress enum Tuple { case Empty case Pair[Hd, Tl] } import Tuple._ type Concat[+Xs <: Tuple, +Ys <: Tuple] <: Tuple = Xs match { case Empty => Ys case Pair[x, xs] => Pair[x, Concat[xs, Ys]] }
  • 32. #2 Typeclass Derivation enum Tree[T] derives Eql, Ordering, Pickling { case Branch(left: Tree[T], right: Tree[T]) case Leaf(elem: T) } given [T: Eql] as Eql[Tree[T]] = Eql.derived given [T: Ordering] as Ordering[Tree[T]] = Ordering.derived given [T: Pickling] as Pickling[Tree[T]] = Pickling.derived this generates: where typeclasses define “derived” methods.  ScalaDays Talk by Miles Sabin
  • 33. #2 Typeclass Derivation “derived” methods use match types, inline and macros to do their work object Eq { inline def derived[T] given (mirror: Mirror.Of[T]): Eq[T] = new Eq[T] { def eql(x: T, y: T): Boolean = inline mirror match { case m: Mirror.SumOf[T] => val ord = m.ordinal(x) ord == m.ordinal(y) && eqlCases[m.ElemTypes](0)(x, y, ord) case m: Mirror.ProductOf[T] => eqlElems[m.ElemTypes](0)(x, y) } }  ScalaDays Talk by Nicolas Stucki
  • 34. #1 Functions Everywhere Scala distinguishes methods from functions. Scala 3 lifts three fundamental capabilities from one to the other. Function types can be: • dependent: • polymorphic: • implicit: trait Graph { type Node; type Edge } type NodeExtractor = (g: Graph) => g.Node type PolyIdentity = [T] => T => T type Executable[T] = given ExecutionContext => T
  • 35. The public vote: (“functions everywhere” was a write-in from Miles)
  • 36. Synergies object PostConditions { opaque type Wrap[T] = T def result[T] given (r: Wrap[T]): T = r def (x: T) ensuring [T] (cond: given Wrap[T] => Boolean): T = assert(cond given x) } import PostConditions.{ensuring, result} List(1, 2, 3) .sum .ensuring(result == 6)
  • 37. Is Scala 3 a New Language?
  • 38. Is Scala 3 a New Language? Yes! • Many language changes, including feature removals. • New constructs improve user experience and on-boarding. • Books will have to be rewritten.
  • 39. Is Scala 3 a New Language? No! • It’s still Scala. • All core constructs remain in place. • Large & practical common subset between Scala 2 and Scala 3. • Programs can cross-build  Dotty compiler, ScalaTest.
  • 40. Is Scala 3 a New Language? It’s a Process • Scala 3.0 keeps most constructs of 2.13, alongside the new ones. • Some constructs will be deprecated and phased out in the 3.x release train. • This requires some temporary duplication. • End result: a more compact and regular language.
  • 41. Replacements Exports + toplevel defs for Package objects Givens for Implicit defs, vals, objects, conversions Extension methods for Implicit classes Inline + staging + for Current macros match types
  • 42. Why So Many New Features At Once? Scala 3 is when the books will be rewritten. Need to get it in now if • it affects foundations, • it simplifies life, especially for learners, • it replaces existing features.
  • 43. Why So Many New Features At Once? Hence, prioritize - Foundations - Simplifications (for developers) - Restrictions over added power and expressiveness
  • 44. How to Get There? • Source compatibility for a large common subset. • Rewrite tools can handle much of the rest • Situation better than for Python 2 vs 3 because of static typing & binary compatibility.  Talk by Lukas Rytz, Wed 16.45
  • 45. Binary Compatibility today: Dotty can link with Scala-2.12 class files. Scala 2 module Dotty module
  • 46. Binary Compatibility today: Dotty can link with Scala-2.12 class files. Scala 2 module Dotty module in the works: Two way compatibility using Tasty as common intermediate format. Scala 2 module Scala 3 module
  • 47. Tasty At The Core Tasty .scala (2.x) .scala (3.x) .class (Java 8) .js .class (Java 11) .out macros analyzers optimizers IDE LSP  Talk by Gullaume Martres, Wed 10.15
  • 48. Binary Compatibility For Scala 3 • The plan is to keep the Tasty format binary compatible over the whole 3.x series. • Compile-from Tasty then allows code to migrate without the current problems of binary compatibility.
  • 49. Try it out: dotty.epfl.ch Thank You

Hinweis der Redaktion

  1. OPEN GAMBIT Multicore. Cloud computing. Containers. You’ll likely agree that the infrastructure for amazing scalability is in place, it’s been well funded. It’s the underpinning that’s required for enterprises to movie en masse to the cloud. But what are they moving? Applications. Applications that run their business, engage their customers, allow them to innovate and enter new markets. Without applications, this infinitely scalable infrastructure is nothing.