Scala in Martin Odersky

Similar documents
The Trouble with Types

The DOT Calculus. (Dependent Object Types) Nada Amin. June 18, Scala Days

Dependent Object Types - A foundation for Scala s type system

The DOT Calculus. (Dependent Object Types) Nada Amin. May 12, flatmap(oslo)

Scala Where It Came From Where It is Going

Research compiler that will become Scala 3 Type system internals redesigned, inspired by DOT, but externally very similar More info:

Scala : an LLVM-targeted Scala compiler

CS162 Week 1. Kyle Dewey. Friday, January 10, 14

CS205: Scalable Software Systems

Philipp Wille. Beyond Scala s Standard Library

Dependent Object Types - A foundation for Scala's type system

G Programming Languages - Fall 2012

...something useful to do with the JVM.

Software System Design and Implementation

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

Type Systems. Today. 1. Organizational Matters. 1. Organizational Matters. Lecture 1 Oct. 20th, 2004 Sebastian Maneth. 1. Organizational Matters

Denotational Semantics. Domain Theory

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

Static type safety guarantees for the operators of a relational database querying system. Cédric Lavanchy

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

Rethinking Scala Macros

CSCI-GA Scripting Languages

State of the Meta, Spring 2015

How We Built Tools That Scale to Millions of Lines of Code

6.001 Notes: Section 4.1

Hiding local state in direct style: a higher-order anti-frame rule

Practical Affine Types and Typestate-Oriented Programming

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

On Meaning Preservation of a Calculus of Records

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference

Chapter 15. Functional Programming Languages

Lecture 1: Overview

Lambda calculus. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 6

CS261 Data Structures. Ordered Array Dynamic Array Implementation

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

Propositional Calculus. Math Foundations of Computer Science

Variables. Substitution

CPS 506 Comparative Programming Languages. Programming Language Paradigm

Chapter 3. Semantics. Topics. Introduction. Introduction. Introduction. Introduction

CS558 Programming Languages

Announcements. CSCI 334: Principles of Programming Languages. Lecture 16: Intro to Scala. Announcements. Squeak demo. Instructor: Dan Barowy

// Body of shortestlists starts here y flatmap { case Nil => Nil case x :: xs => findshortest(list(x), xs)

Scala Concurrency and Parallel Collections

Functional Programming and Haskell

Scala. Introduction. Scala

Arne Brüsch Philipp Wille. Pattern Matching Syntax

Variables and Bindings

Induction and Semantics in Dafny

CS558 Programming Languages

Featherweight Scala. Week 14

CompSci 220. Programming Methodology 12: Functional Data Structures

Functional Programming Languages (FPL)

Axiomatic Rules. Lecture 18: Axiomatic Semantics & Type Safety. Correctness using Axioms & Rules. Axiomatic Rules. Steps in Proof

Improving Scala's Safe Type-Level Abstraction

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals

Global Optimization. Lecture Outline. Global flow analysis. Global constant propagation. Liveness analysis. Local Optimization. Global Optimization

Optimizing Higher-Order Functions in Scala

an overview Alceste Scalas Programming languages reading group

Functional Programming. Big Picture. Design of Programming Languages

Formal Systems and their Applications

Last class. CS Principles of Programming Languages. Introduction. Outline

An introduction to Scheme

Introduction to Spark

Chapter 3 (part 3) Describing Syntax and Semantics

Bibliography. Analyse et Conception Formelle. Lesson 5. Crash Course on Scala. Scala in a nutshell. Outline

CS 11 Haskell track: lecture 1

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

Scala Style Guide Spring 2018

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

Propositional Calculus. CS 270: Mathematical Foundations of Computer Science Jeremy Johnson

INF 212/CS 253 Type Systems. Instructors: Harry Xu Crista Lopes

CMSC 330: Organization of Programming Languages. Operational Semantics

Programming Systems in Artificial Intelligence Functional Programming

Multi-event IDS Categories. Introduction to Misuse Intrusion Detection Systems (IDS) Formal Specification of Intrusion Signatures and Detection Rules

Recap: Functions as first-class values

(Refer Slide Time: 4:00)

Chapter 5 Names, Binding, Type Checking and Scopes

Enter your UID and password. Make sure you have popups allowed for this site.

Fundamental mathematical techniques reviewed: Mathematical induction Recursion. Typically taught in courses such as Calculus and Discrete Mathematics.

Homework 3. OPTIONAL PROBLEMS (No due date)

AXIOMS FOR THE INTEGERS

Relational Algebra. Relational Query Languages

Lambda Calculus and Type Inference

Outline. What is semantics? Denotational semantics. Semantics of naming. What is semantics? 2 / 21

Harnessing Java with Scala

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

CS6202: Advanced Topics in Programming Languages and Systems Lecture 0 : Overview

Data Structure and Algorithm Midterm Reference Solution TA

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Programming Languages Third Edition

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

Scala, Your Next Programming Language

F# for Industrial Applications Worth a Try?

Stop coding Pascal. Saturday, April 6, 13

Compilers and computer architecture: Semantic analysis

Lecture Compiler Middle-End

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Sections p.

LOGIC AND DISCRETE MATHEMATICS

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson

Transcription:

Scala in 2016 - Martin Odersky

2015 was on the quiet side Maturing tools: 2.11.x, IDEs, sbt Steady growth indeed.com jobs google trends

In 2016, things will move again Scala 2.12 release Rethinking the Scala libraries New target platforms DOT and dotty

Scala 2.12 Optimized for Java 8 Uses Java 8 s lambdas and default methods for shorter code and faster execution speed. Projected release date: mid 2016. In case you are still on Java 6/7, Scala 2.11 will be around for a while.

Beyond 2.12 Scala 2.13 will focus on the libraries Plans to revamp collections Simpler to use More in line with Spark usage Better lazy collections (views)

Beyond 2.12 Scala 2.13 will focus on the libraries Better modularization. One option would be a split: Scala core Scala stdlib Scala platform Your input and help is vital for this.

New Platforms Scala JS: 0.6.6 released js.tuplen, a JS equivalent of Scala tuples Support for JUnit Faster linking New website Denys Shabalin is working on a LLVM target. Help and contributions welcome!

DOT We finally have a proven foundation for Scala! The DOT calculus talks about a minimal language subset, chosen so that we can make and prove formal statements about it we can encode much of the rest of the language in it. This concludes an 8 year effort It opens the door to do language work with much better confidence than before.

DOT Terms Translated to Scala notation, the language covered by DOT is: Value v = (x: T) => t Function new { x: T => d } Object Definition d = def a = t Method definition type A = T Type Term t = v Value x Variable t 1 (t 2 ) Application t.a Selection { val x = t 1 ; t 2 } Local definition.

DOT Types The Types covered by DOT are: Type T = Any Top type Nothing Bottom type x.a Selection (x: T 1 ) => T 2 Function { def a: T } Method declaration { type T >: T 1 <: T 2 } Type declaration T 1 & T 2 Intersection { x => T } Recursion

Type Soundness The following property was shown with a mechanized proof: If a term t has type T, and evaluation of t terminates: the result will be a value v of type T. Why is This Important? It gives us a technique to reason about correctness of other language features.

dotty dotty is working name for our new Scala compiler. Builds on DOT in its internal data structures. Generics get expressed as type members. Supports an evolution of the Scala programming language. A first alpha release is expected this year. Targeted at contributors and experimenters.

dotty Technical Data A bit more than half the size of the current Scala compiler, nsc. dotty: 45 KLoc nsc: 75 KLoc About twice the speed of nsc. should improve significantly in the future.

dotty Architecture Scala Sources Scala Sources dotty Frontend nsc AST TASTY Pickled AST dotty Transforms nsc Transforms Simplified AST Simplified AST GenBCode Classfiles

Language evolution Overall goal: Make language simpler to use Improve safety guarantees, reduce boilerplate. Some new features supported by dotty: Trait parameters Intersection types Union types

Added: Trait Parameters Can parameterize traits just like classes. trait Logging(f: File) { f.open() onexit(f.close()) def log(msg: String) = f.write(msg) } class C extends Logging(new File("log.data"))

Removed: Early Definitions The following is no longer supported: trait Logging { val f: File f.open() onexit(f.close()) def log(msg: String) = f.write(msg) } class C extends { val f = new File("log.data ) } with Logging

Trait or Class? Classes and traits now have largely the same capabilities. Rule of thumb: When it's fully defined, make it a class When it's abstract, make it a trait Abstract classes are retained mainly for Java interop and for optimization.

Added: Intersection Types A & B // Values that are both an A and a B Intersection types replace compound types A with B What s the difference?

Difference between A & B and A with B Consider: trait A { def f: A } trait B { def f: B } val ab: A & B val ba: B & A Give the types of: ab.f:? ba.f:?

Difference between A & B and A with B Consider: trait A { def f: A } trait B { def f: B } val ab: A & B val ba: B & A Give the types of: ab.f: A & B ba.f:?

Difference between A & B and A with B Consider: trait A { def f: A } trait B { def f: B } val ab: A & B val ba: B & A Give the types of: ab.f: A & B ba.f: A & B

Difference between A & B and A with B Consider: trait A { def f: A } trait B { def f: B } val ab: A & B val ba: B & A Give the types of: ab.f: B & A ba.f: B & A Both work, since we have A & B = B & A

Difference between A & B and A with B Consider: trait A { def f: A } trait B { def f: B } val ab: A with B val ba: B with A Give the types of: ab.f:? ba.f:?

Difference between A & B and A with B Consider: trait A { def f: A } trait B { def f: B } val ab: A with B val ba: B with A Give the types of: ab.f: B ba.f:?

Difference between A & B and A with B Consider: trait A { def f: A } trait B { def f: B } val ab: A with B val ba: B with A Give the types of: ab.f: B ba.f: A

Difference between A & B and A with B Consider: trait A { def f: A } trait B { def f: B } val ab: A with B val ba: B with A Give the types of: ab.f: B ba.f: A Hence, A & B!= B & A. & is commutative, but with isn t.

Added: Union Types Union types are the dual of intersection types. Example: A B // Values that are an A or a B String List[Int] Use union types for ad-hoc open sums ad-hoc: Can't plan ahead to define common supertrait open: Arbitrary number of operands A lightweight, efficient alternative to Either.

Eliminated: Exploding lubs Scala's type inferencer often needs to compute the least upper bound (lub) of two or more types. For instance, in an if: scala> if (true) Vector(0) else List(1, 2, 3) res0: scala.collection.immutable.seq[int] with scala.collection.abstractseq[int] with Serializable = Vector(0)

Eliminated: Exploding lubs But sometimes the least upper bound is very large:

Eliminated: Exploding lubs Reformatted: scala> if (true) Vector(0) else Range(0, 1) res0: scala.collection.immutable.indexedseq[int] with scala.collection.abstractseq[int] with Serializable with scala.collection.customparallelizable[ Int, scala.collection.parallel.immutable.parseq[int] with Serializable{ def seq: scala.collection.immutable.indexedseq[int] with scala.collection.abstractseq[int] with Serializable with scala.collection.customparallelizable[...

Eliminated: Exploding lubs Union types avoid exploding lubs because the least upper bound of A and B is simply A B. dotty> If (true) Vector(0) else Range(1) res0: scala.collection.immutable.vector[int] scala.collection.immutable.list[int] = Vector(0)

Who s working on all this? Scala is very much community driven. Your contribution counts!

Stewardship We are about to create a new entity for helping organize open source work on Scala. The Scala Center will act like a foundation. It will be organized as an independent unit of EPFL.

Scala Center Missions The Center has two missions: 1. Organize open source projects around Scala. 2. Organize and develop online teaching. We need your help to do this! If you want to help us, contact me after the talk. Thank You!