SlideShare a Scribd company logo
1 of 31
Download to read offline
Implementing Higher-
Kinded Types in Dotty
Martin Odersky
Scala Symposium, October 2016, Amsterdam
joint work with
Guillaume Martres, Dmitry Petrashko
Dotty
• The new Scala compiler developed at LAMP
• Based on DOT as a theoretical foundation
• Long-standing question: How to implement
higher-kinded types on these foundations?
• The paper and talk investigate 4 (!) different
solutions to do so.
Timeline
Simple
Encoding
Projection
Encoding
Refinement
Encoding
Direct
Repr.
Foundations: DOT
The DOT calculus is intended to be a minimal
foundation of Scala.
Its type structure is a blueprint for the types used
internally in the compiler.
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
t1(t2) Application
t.a Selection
{ val x = t1; t2 } Local definition.
DOT Types
The Types covered by DOT are:
Type T = Any Top type
Nothing Bottom type
x.A Selection
(x: T1) => T2 Function
{ def a: T } Method declaration
{ type T >: T1 <: T2 } Type declaration
T1 & T2 Intersection
{ x => T } Recursion
DOT Types
The Types covered by DOT are:
Type T = Any Top type
Nothing Bottom type
x.A Selection
(x: T1) => T2 Function
{ def a: T } Method declaration
{ type T >: T1 <: T2 } Type declaration
T1 & T2 Intersection
{ x => T } Recursion
Should Scala have these?
DOT Types
The Types covered by DOT are:
Type T = Any Top type
Nothing Bottom type
x.A Selection
(x: T1) => T2 Function
{ def a: T } Method declaration
{ type T >: T1 <: T2 } Type declaration
T1 & T2 Intersection
{ x => T } RecursionScala has only refinements
T { d1 … dn}
with this as self reference.
Encoding Type Parameters
Lists, Encoded
A Variant of Variance
Variance, Encoded
=
Why Encode Parameterization?
• One fundamental concept (type member
selection) instead of two.
• Clarifies interaction between parameterization
and membership.
E.g.
List[_ <: Number] = List { type T <: Number }
The Simple Encoding
Simple
Encoding
Higher-Kinded Types
Problem: How to encode
type C[X] = List[X]
type C[+X <: Number] <: List[X]
?
Idea: Generalize definition of type parameters:
• of a class: designated member types
• of an alias type: type params of its alias
• of an abstract type: type params of upper bound
The Simple Encoding
Problem: How to encode
type C[X] <: List[X]
type D[X <: Number] = Cons[X]
?
This leads to:
type C <: List
type D = List { type T <: Number }
The Simple Encoding
Problem: How to encode
type C[X] <: List[X]
type D[X <: Number] = Cons[X]
?
This leads to:
type C <: List List[_]
type D = List { type T <: Number } List[_ <: Number]
Note that these encodings can also be seen as
wildcard (existential) types!
Limitations of the Simple Encoding
Unfortunately, there are things that can’t be
encoded that way:
type Rep[T] = T
type LL[T] = List[List[T]]
type RMap[V, K] = Map[K, V]
What To Do?
The Projection Encoding
Projection
Encoding
The Projection Encoding
Idea (originally due to Adriaan Moors):
Simulate type application using type selection.
E.g.
type C[X] <: List[X]
becomes
type C <: Lambda$P {
type $hk0
type $Apply <: List { type T = $hk0 }
}
The Projection Encoding
Idea (originally due to Adriaan Moors):
Simulate type application using type selection.
Then
C[String]
becomes
C { type $hk0 = String } # $Apply
The Projection Encoding
Idea (originally due to Adriaan Moors):
Simulate type application using type selection.
If we instantiate C to List, say, we get:
type C = Lambda$P {
type $hk0
type $Apply = List { type T = $hk0 }
}
The Projection Encoding
Hence,
C[String]
= C { type $hk0 = String } # $Apply
= Lambda$P {
type $hk0; type $Apply = List { type T = $hk0 }
} { type $hk0 = String } # $Apply
=:=
List { type $hk0 = String }
= List[String]
Where “=:=” is interpreted as “being mutual subtype of”.
Problems with the Projection Enc.
• There were several, but the killer was:
It relies on type projection T#U, which is unsound in
general and will therefore be phased out.
• See the paper for a discussion in detail.
The Refinement Encoding
Refinement
Encoding
The Refinement Encoding
Idea:
Encode
type C[X] <: List[X]
C[String]
as
type C <: { z => List { type T = $hk0 }
type $hk0 }
C { type $hk0 = String }
This also had several problems which are described in
the paper.
In the end…
… we represented hk types directly, using special
type forms for
• Type lambda: [X] -> T TypeLambda
• Higher-kinded
type application: C[T] HKApply
• A beta reduction rule:
([X] -> T)[U] à [X := U]T
• Rules for subtyping, type inference …
Implementation Data
Simple
Encoding
Projection
Encoding
Refinement
Encoding
Direct
Repr.
Total type-
checker + core:
28’000 cloc
Evaluation
• The simple encoding is a modest extension for a
language with wildcards or variance that wants to
support basic concepts associated with hk types.
• Cheap way to get a lot of the advantages of hk.
• Difficulty: Explain what’s legal and what is not.
• Other encodings were less successful than they
looked at first.
• A direct representation is needed for robust
support of full higher kinded types.
Still Missing
• A theory that explains what the compiler did
in terms of DOT.
• Hopefully, we can find something that’s small
and fits well.
A Take Away
• Compiler hacking is a possible way to validate
ideas
• But it may not be the most efficient one.
• If we would have a better theory how higher-
kinded types fit into DOT, we could have avoided
some costly experiments.

More Related Content

What's hot

Writing a fast HTTP parser
Writing a fast HTTP parserWriting a fast HTTP parser
Writing a fast HTTP parserfukamachi
 
An overview of Neo4j Internals
An overview of Neo4j InternalsAn overview of Neo4j Internals
An overview of Neo4j InternalsTobias Lindaaker
 
Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningOSSCube
 
Neo4j Drivers Best Practices
Neo4j Drivers Best PracticesNeo4j Drivers Best Practices
Neo4j Drivers Best PracticesNeo4j
 
Postgresql Database Administration Basic - Day1
Postgresql  Database Administration Basic  - Day1Postgresql  Database Administration Basic  - Day1
Postgresql Database Administration Basic - Day1PoguttuezhiniVP
 
Let's Build an Inverted Index: Introduction to Apache Lucene/Solr
Let's Build an Inverted Index: Introduction to Apache Lucene/SolrLet's Build an Inverted Index: Introduction to Apache Lucene/Solr
Let's Build an Inverted Index: Introduction to Apache Lucene/SolrSease
 
Developer Intro Deck-PowerPoint - Download for Speaker Notes
Developer Intro Deck-PowerPoint - Download for Speaker NotesDeveloper Intro Deck-PowerPoint - Download for Speaker Notes
Developer Intro Deck-PowerPoint - Download for Speaker NotesMax De Marzi
 
Understanding MySQL Performance through Benchmarking
Understanding MySQL Performance through BenchmarkingUnderstanding MySQL Performance through Benchmarking
Understanding MySQL Performance through BenchmarkingLaine Campbell
 
Trino at linkedIn - 2021
Trino at linkedIn - 2021Trino at linkedIn - 2021
Trino at linkedIn - 2021Akshay Rai
 
Graph Gurus 23: Best Practices To Model Your Data Using A Graph Database
Graph Gurus 23: Best Practices To Model Your Data Using A Graph DatabaseGraph Gurus 23: Best Practices To Model Your Data Using A Graph Database
Graph Gurus 23: Best Practices To Model Your Data Using A Graph DatabaseTigerGraph
 
How to Build a Scylla Database Cluster that Fits Your Needs
How to Build a Scylla Database Cluster that Fits Your NeedsHow to Build a Scylla Database Cluster that Fits Your Needs
How to Build a Scylla Database Cluster that Fits Your NeedsScyllaDB
 
TensorFlowOnSpark: Scalable TensorFlow Learning on Spark Clusters
TensorFlowOnSpark: Scalable TensorFlow Learning on Spark ClustersTensorFlowOnSpark: Scalable TensorFlow Learning on Spark Clusters
TensorFlowOnSpark: Scalable TensorFlow Learning on Spark ClustersDataWorks Summit
 
Parquet - Data I/O - Philadelphia 2013
Parquet - Data I/O - Philadelphia 2013Parquet - Data I/O - Philadelphia 2013
Parquet - Data I/O - Philadelphia 2013larsgeorge
 
Polymorphic Table Functions in SQL
Polymorphic Table Functions in SQLPolymorphic Table Functions in SQL
Polymorphic Table Functions in SQLChris Saxon
 
SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?Brent Ozar
 
GraphQL ♥︎ GraphDB
GraphQL ♥︎ GraphDBGraphQL ♥︎ GraphDB
GraphQL ♥︎ GraphDBGraphRM
 

What's hot (20)

Writing a fast HTTP parser
Writing a fast HTTP parserWriting a fast HTTP parser
Writing a fast HTTP parser
 
An overview of Neo4j Internals
An overview of Neo4j InternalsAn overview of Neo4j Internals
An overview of Neo4j Internals
 
Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuning
 
Neo4j Drivers Best Practices
Neo4j Drivers Best PracticesNeo4j Drivers Best Practices
Neo4j Drivers Best Practices
 
Postgresql Database Administration Basic - Day1
Postgresql  Database Administration Basic  - Day1Postgresql  Database Administration Basic  - Day1
Postgresql Database Administration Basic - Day1
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Let's Build an Inverted Index: Introduction to Apache Lucene/Solr
Let's Build an Inverted Index: Introduction to Apache Lucene/SolrLet's Build an Inverted Index: Introduction to Apache Lucene/Solr
Let's Build an Inverted Index: Introduction to Apache Lucene/Solr
 
Developer Intro Deck-PowerPoint - Download for Speaker Notes
Developer Intro Deck-PowerPoint - Download for Speaker NotesDeveloper Intro Deck-PowerPoint - Download for Speaker Notes
Developer Intro Deck-PowerPoint - Download for Speaker Notes
 
Understanding MySQL Performance through Benchmarking
Understanding MySQL Performance through BenchmarkingUnderstanding MySQL Performance through Benchmarking
Understanding MySQL Performance through Benchmarking
 
Trino at linkedIn - 2021
Trino at linkedIn - 2021Trino at linkedIn - 2021
Trino at linkedIn - 2021
 
Graph database
Graph databaseGraph database
Graph database
 
Graph Gurus 23: Best Practices To Model Your Data Using A Graph Database
Graph Gurus 23: Best Practices To Model Your Data Using A Graph DatabaseGraph Gurus 23: Best Practices To Model Your Data Using A Graph Database
Graph Gurus 23: Best Practices To Model Your Data Using A Graph Database
 
How to Build a Scylla Database Cluster that Fits Your Needs
How to Build a Scylla Database Cluster that Fits Your NeedsHow to Build a Scylla Database Cluster that Fits Your Needs
How to Build a Scylla Database Cluster that Fits Your Needs
 
How to Use JSON in MySQL Wrong
How to Use JSON in MySQL WrongHow to Use JSON in MySQL Wrong
How to Use JSON in MySQL Wrong
 
TensorFlowOnSpark: Scalable TensorFlow Learning on Spark Clusters
TensorFlowOnSpark: Scalable TensorFlow Learning on Spark ClustersTensorFlowOnSpark: Scalable TensorFlow Learning on Spark Clusters
TensorFlowOnSpark: Scalable TensorFlow Learning on Spark Clusters
 
Parquet - Data I/O - Philadelphia 2013
Parquet - Data I/O - Philadelphia 2013Parquet - Data I/O - Philadelphia 2013
Parquet - Data I/O - Philadelphia 2013
 
SQLServer Database Structures
SQLServer Database Structures SQLServer Database Structures
SQLServer Database Structures
 
Polymorphic Table Functions in SQL
Polymorphic Table Functions in SQLPolymorphic Table Functions in SQL
Polymorphic Table Functions in SQL
 
SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?
 
GraphQL ♥︎ GraphDB
GraphQL ♥︎ GraphDBGraphQL ♥︎ GraphDB
GraphQL ♥︎ GraphDB
 

Viewers also liked

Union Types and Literal Singleton Types in Scala (and Typescript)
Union Types and Literal Singleton Types in Scala (and Typescript)Union Types and Literal Singleton Types in Scala (and Typescript)
Union Types and Literal Singleton Types in Scala (and Typescript)Joost de Vries
 
Introduction to Risk-Neutral Pricing
Introduction to Risk-Neutral PricingIntroduction to Risk-Neutral Pricing
Introduction to Risk-Neutral PricingAshwin Rao
 
Columbia CS - Roles in Quant Finance
Columbia CS - Roles in Quant Finance Columbia CS - Roles in Quant Finance
Columbia CS - Roles in Quant Finance Ashwin Rao
 
Stanford FinMath - Careers in Quant Finance
Stanford FinMath - Careers in Quant FinanceStanford FinMath - Careers in Quant Finance
Stanford FinMath - Careers in Quant FinanceAshwin Rao
 
Careers in Quant Finance talk at UCLA Financial Engineering
Careers in Quant Finance talk at UCLA Financial EngineeringCareers in Quant Finance talk at UCLA Financial Engineering
Careers in Quant Finance talk at UCLA Financial EngineeringAshwin Rao
 
Berkeley Financial Engineering - Guidance on Careers in Quantitative Finance
Berkeley Financial Engineering - Guidance on Careers in Quantitative FinanceBerkeley Financial Engineering - Guidance on Careers in Quantitative Finance
Berkeley Financial Engineering - Guidance on Careers in Quantitative FinanceAshwin Rao
 
Careers outside Academia - USC Computer Science Masters and Ph.D. Students
Careers outside Academia - USC Computer Science Masters and Ph.D. StudentsCareers outside Academia - USC Computer Science Masters and Ph.D. Students
Careers outside Academia - USC Computer Science Masters and Ph.D. StudentsAshwin Rao
 
IIT Bombay - First Steps to a Successful Career
IIT Bombay - First Steps to a Successful CareerIIT Bombay - First Steps to a Successful Career
IIT Bombay - First Steps to a Successful CareerAshwin Rao
 
Pseudo and Quasi Random Number Generation
Pseudo and Quasi Random Number GenerationPseudo and Quasi Random Number Generation
Pseudo and Quasi Random Number GenerationAshwin Rao
 
Career Advice at University College of London, Mathematics Department.
Career Advice at University College of London, Mathematics Department.Career Advice at University College of London, Mathematics Department.
Career Advice at University College of London, Mathematics Department.Ashwin Rao
 
The Fuss about || Haskell | Scala | F# ||
The Fuss about || Haskell | Scala | F# ||The Fuss about || Haskell | Scala | F# ||
The Fuss about || Haskell | Scala | F# ||Ashwin Rao
 
Introduction to Stochastic calculus
Introduction to Stochastic calculusIntroduction to Stochastic calculus
Introduction to Stochastic calculusAshwin Rao
 
Careers in Quant Finance - IIT Delhi
Careers in Quant Finance - IIT DelhiCareers in Quant Finance - IIT Delhi
Careers in Quant Finance - IIT DelhiAshwin Rao
 
Abstract Algebra in 3 Hours
Abstract Algebra in 3 HoursAbstract Algebra in 3 Hours
Abstract Algebra in 3 HoursAshwin Rao
 
Fitness 101 - Mumbai
Fitness 101 - MumbaiFitness 101 - Mumbai
Fitness 101 - MumbaiAshwin Rao
 
HOW can India's Parliament function better?
HOW can India's Parliament function better?HOW can India's Parliament function better?
HOW can India's Parliament function better?Yogesh Upadhyaya
 

Viewers also liked (20)

From DOT to Dotty
From DOT to DottyFrom DOT to Dotty
From DOT to Dotty
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
Scalax
ScalaxScalax
Scalax
 
Union Types and Literal Singleton Types in Scala (and Typescript)
Union Types and Literal Singleton Types in Scala (and Typescript)Union Types and Literal Singleton Types in Scala (and Typescript)
Union Types and Literal Singleton Types in Scala (and Typescript)
 
Flatmap
FlatmapFlatmap
Flatmap
 
Introduction to Risk-Neutral Pricing
Introduction to Risk-Neutral PricingIntroduction to Risk-Neutral Pricing
Introduction to Risk-Neutral Pricing
 
Columbia CS - Roles in Quant Finance
Columbia CS - Roles in Quant Finance Columbia CS - Roles in Quant Finance
Columbia CS - Roles in Quant Finance
 
Stanford FinMath - Careers in Quant Finance
Stanford FinMath - Careers in Quant FinanceStanford FinMath - Careers in Quant Finance
Stanford FinMath - Careers in Quant Finance
 
Careers in Quant Finance talk at UCLA Financial Engineering
Careers in Quant Finance talk at UCLA Financial EngineeringCareers in Quant Finance talk at UCLA Financial Engineering
Careers in Quant Finance talk at UCLA Financial Engineering
 
Berkeley Financial Engineering - Guidance on Careers in Quantitative Finance
Berkeley Financial Engineering - Guidance on Careers in Quantitative FinanceBerkeley Financial Engineering - Guidance on Careers in Quantitative Finance
Berkeley Financial Engineering - Guidance on Careers in Quantitative Finance
 
Careers outside Academia - USC Computer Science Masters and Ph.D. Students
Careers outside Academia - USC Computer Science Masters and Ph.D. StudentsCareers outside Academia - USC Computer Science Masters and Ph.D. Students
Careers outside Academia - USC Computer Science Masters and Ph.D. Students
 
IIT Bombay - First Steps to a Successful Career
IIT Bombay - First Steps to a Successful CareerIIT Bombay - First Steps to a Successful Career
IIT Bombay - First Steps to a Successful Career
 
Pseudo and Quasi Random Number Generation
Pseudo and Quasi Random Number GenerationPseudo and Quasi Random Number Generation
Pseudo and Quasi Random Number Generation
 
Career Advice at University College of London, Mathematics Department.
Career Advice at University College of London, Mathematics Department.Career Advice at University College of London, Mathematics Department.
Career Advice at University College of London, Mathematics Department.
 
The Fuss about || Haskell | Scala | F# ||
The Fuss about || Haskell | Scala | F# ||The Fuss about || Haskell | Scala | F# ||
The Fuss about || Haskell | Scala | F# ||
 
Introduction to Stochastic calculus
Introduction to Stochastic calculusIntroduction to Stochastic calculus
Introduction to Stochastic calculus
 
Careers in Quant Finance - IIT Delhi
Careers in Quant Finance - IIT DelhiCareers in Quant Finance - IIT Delhi
Careers in Quant Finance - IIT Delhi
 
Abstract Algebra in 3 Hours
Abstract Algebra in 3 HoursAbstract Algebra in 3 Hours
Abstract Algebra in 3 Hours
 
Fitness 101 - Mumbai
Fitness 101 - MumbaiFitness 101 - Mumbai
Fitness 101 - Mumbai
 
HOW can India's Parliament function better?
HOW can India's Parliament function better?HOW can India's Parliament function better?
HOW can India's Parliament function better?
 

Similar to Implementing Higher-Kinded Types in Dotty

Scala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowScala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowLightbend
 
Legacy lambda code
Legacy lambda codeLegacy lambda code
Legacy lambda codePeter Lawrey
 
A category-theoretic view of model-driven
A category-theoretic view of model-drivenA category-theoretic view of model-driven
A category-theoretic view of model-drivendslmeinte
 
12TypeSystem.pdf
12TypeSystem.pdf12TypeSystem.pdf
12TypeSystem.pdfMdAshik35
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingEelco Visser
 
Types, classes and concepts
Types, classes and conceptsTypes, classes and concepts
Types, classes and conceptsNicola Bonelli
 
Csc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declarationCsc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declarationIIUM
 
Csc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declarationCsc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declarationIIUM
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)bolovv
 
Algorithms and problem solving.pptx
Algorithms and problem solving.pptxAlgorithms and problem solving.pptx
Algorithms and problem solving.pptxaikomo1
 
Crystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafiosCrystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafiosBrian Cardiff
 
Tools for reading papers
Tools for reading papersTools for reading papers
Tools for reading papersJack Fox
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
The Goal and The Journey - Turning back on one year of C++14 Migration
The Goal and The Journey - Turning back on one year of C++14 MigrationThe Goal and The Journey - Turning back on one year of C++14 Migration
The Goal and The Journey - Turning back on one year of C++14 MigrationJoel Falcou
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideNascenia IT
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic FundamentalsDivyaR219113
 

Similar to Implementing Higher-Kinded Types in Dotty (20)

Scala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowScala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To Know
 
Legacy lambda code
Legacy lambda codeLegacy lambda code
Legacy lambda code
 
A category-theoretic view of model-driven
A category-theoretic view of model-drivenA category-theoretic view of model-driven
A category-theoretic view of model-driven
 
12TypeSystem.pdf
12TypeSystem.pdf12TypeSystem.pdf
12TypeSystem.pdf
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
 
coding.pdf
coding.pdfcoding.pdf
coding.pdf
 
LINQ.ppt
LINQ.pptLINQ.ppt
LINQ.ppt
 
Types, classes and concepts
Types, classes and conceptsTypes, classes and concepts
Types, classes and concepts
 
Csc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declarationCsc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declaration
 
Csc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declarationCsc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declaration
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
 
Algorithms and problem solving.pptx
Algorithms and problem solving.pptxAlgorithms and problem solving.pptx
Algorithms and problem solving.pptx
 
Crystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafiosCrystal: tipos, peculiaridades y desafios
Crystal: tipos, peculiaridades y desafios
 
Tools for reading papers
Tools for reading papersTools for reading papers
Tools for reading papers
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Ch6.ppt
Ch6.pptCh6.ppt
Ch6.ppt
 
The Goal and The Journey - Turning back on one year of C++14 Migration
The Goal and The Journey - Turning back on one year of C++14 MigrationThe Goal and The Journey - Turning back on one year of C++14 Migration
The Goal and The Journey - Turning back on one year of C++14 Migration
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation Guide
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic Fundamentals
 

More from Martin Odersky

What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin Odersky
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin Odersky
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San FranciscoMartin Odersky
 
The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of ScalaMartin Odersky
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationMartin Odersky
 
flatMap Oslo presentation slides
flatMap Oslo presentation slidesflatMap Oslo presentation slides
flatMap Oslo presentation slidesMartin Odersky
 
Oscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleOscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleMartin Odersky
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange openingMartin Odersky
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 

More from Martin Odersky (13)

scalar.pdf
scalar.pdfscalar.pdf
scalar.pdf
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Simplicitly
SimplicitlySimplicitly
Simplicitly
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of Scala
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
flatMap Oslo presentation slides
flatMap Oslo presentation slidesflatMap Oslo presentation slides
flatMap Oslo presentation slides
 
Devoxx
DevoxxDevoxx
Devoxx
 
Oscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleOscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simple
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange opening
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 

Recently uploaded

Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxFIDO Alliance
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governanceWSO2
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxFIDO Alliance
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingWSO2
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...caitlingebhard1
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfdanishmna97
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptxFIDO Alliance
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....rightmanforbloodline
 

Recently uploaded (20)

Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 

Implementing Higher-Kinded Types in Dotty

  • 1. Implementing Higher- Kinded Types in Dotty Martin Odersky Scala Symposium, October 2016, Amsterdam joint work with Guillaume Martres, Dmitry Petrashko
  • 2. Dotty • The new Scala compiler developed at LAMP • Based on DOT as a theoretical foundation • Long-standing question: How to implement higher-kinded types on these foundations? • The paper and talk investigate 4 (!) different solutions to do so.
  • 4. Foundations: DOT The DOT calculus is intended to be a minimal foundation of Scala. Its type structure is a blueprint for the types used internally in the compiler.
  • 5. 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 t1(t2) Application t.a Selection { val x = t1; t2 } Local definition.
  • 6. DOT Types The Types covered by DOT are: Type T = Any Top type Nothing Bottom type x.A Selection (x: T1) => T2 Function { def a: T } Method declaration { type T >: T1 <: T2 } Type declaration T1 & T2 Intersection { x => T } Recursion
  • 7. DOT Types The Types covered by DOT are: Type T = Any Top type Nothing Bottom type x.A Selection (x: T1) => T2 Function { def a: T } Method declaration { type T >: T1 <: T2 } Type declaration T1 & T2 Intersection { x => T } Recursion Should Scala have these?
  • 8. DOT Types The Types covered by DOT are: Type T = Any Top type Nothing Bottom type x.A Selection (x: T1) => T2 Function { def a: T } Method declaration { type T >: T1 <: T2 } Type declaration T1 & T2 Intersection { x => T } RecursionScala has only refinements T { d1 … dn} with this as self reference.
  • 11. A Variant of Variance
  • 13. Why Encode Parameterization? • One fundamental concept (type member selection) instead of two. • Clarifies interaction between parameterization and membership. E.g. List[_ <: Number] = List { type T <: Number }
  • 15. Higher-Kinded Types Problem: How to encode type C[X] = List[X] type C[+X <: Number] <: List[X] ? Idea: Generalize definition of type parameters: • of a class: designated member types • of an alias type: type params of its alias • of an abstract type: type params of upper bound
  • 16. The Simple Encoding Problem: How to encode type C[X] <: List[X] type D[X <: Number] = Cons[X] ? This leads to: type C <: List type D = List { type T <: Number }
  • 17. The Simple Encoding Problem: How to encode type C[X] <: List[X] type D[X <: Number] = Cons[X] ? This leads to: type C <: List List[_] type D = List { type T <: Number } List[_ <: Number] Note that these encodings can also be seen as wildcard (existential) types!
  • 18. Limitations of the Simple Encoding Unfortunately, there are things that can’t be encoded that way: type Rep[T] = T type LL[T] = List[List[T]] type RMap[V, K] = Map[K, V] What To Do?
  • 20. The Projection Encoding Idea (originally due to Adriaan Moors): Simulate type application using type selection. E.g. type C[X] <: List[X] becomes type C <: Lambda$P { type $hk0 type $Apply <: List { type T = $hk0 } }
  • 21. The Projection Encoding Idea (originally due to Adriaan Moors): Simulate type application using type selection. Then C[String] becomes C { type $hk0 = String } # $Apply
  • 22. The Projection Encoding Idea (originally due to Adriaan Moors): Simulate type application using type selection. If we instantiate C to List, say, we get: type C = Lambda$P { type $hk0 type $Apply = List { type T = $hk0 } }
  • 23. The Projection Encoding Hence, C[String] = C { type $hk0 = String } # $Apply = Lambda$P { type $hk0; type $Apply = List { type T = $hk0 } } { type $hk0 = String } # $Apply =:= List { type $hk0 = String } = List[String] Where “=:=” is interpreted as “being mutual subtype of”.
  • 24. Problems with the Projection Enc. • There were several, but the killer was: It relies on type projection T#U, which is unsound in general and will therefore be phased out. • See the paper for a discussion in detail.
  • 26. The Refinement Encoding Idea: Encode type C[X] <: List[X] C[String] as type C <: { z => List { type T = $hk0 } type $hk0 } C { type $hk0 = String } This also had several problems which are described in the paper.
  • 27. In the end… … we represented hk types directly, using special type forms for • Type lambda: [X] -> T TypeLambda • Higher-kinded type application: C[T] HKApply • A beta reduction rule: ([X] -> T)[U] à [X := U]T • Rules for subtyping, type inference …
  • 29. Evaluation • The simple encoding is a modest extension for a language with wildcards or variance that wants to support basic concepts associated with hk types. • Cheap way to get a lot of the advantages of hk. • Difficulty: Explain what’s legal and what is not. • Other encodings were less successful than they looked at first. • A direct representation is needed for robust support of full higher kinded types.
  • 30. Still Missing • A theory that explains what the compiler did in terms of DOT. • Hopefully, we can find something that’s small and fits well.
  • 31. A Take Away • Compiler hacking is a possible way to validate ideas • But it may not be the most efficient one. • If we would have a better theory how higher- kinded types fit into DOT, we could have avoided some costly experiments.