SlideShare a Scribd company logo
Subtyping
Machines
Ori Roth
1
Overview
Goal
Investigate the connection between subtyping and
tree languages
Method
Formalize the computability of subtyping with the
subtyping machine
2/21
Subtyping
Scope
Declaration-site nominal subtyping with variance
(Kennedy and Pierce 2007)
What is subtyping?
A type system decision problem
t1 <: t2
3/21
Subtyping
class b : a {}
a x = new b(); ✓ // b <: a
x = new Set(); ✗
Subtyping is everywhere
• Variable assignments
• Method arguments
4/21
Subtyping
Subtyping with type parameters
Collection<b> x = new List<b>(); ✓
List<a> list_b = new List<b>(); ???
5/21
Subtyping
Subtyping with type parameters
Collection<b> x = new List<b>(); ✓
List<a> list_b = new List<b>(); ✗
list_b.add(new a()); ✗
5/21
Subtyping
Subtyping with type parameters
Collection<b> x = new List<b>(); ✓
List<a> list_b = new List<b>(); ✗
list_b.add(new a()); ✗
5/21
List<b> list_a = new List<a>(); ✗
b y = list_a.get(0); ✗
Variance
Covariance
More derived type arguments
ReadOnlyList<a> x = new ReadOnlyList<b>(); ✓
a y = x.get(0); ✓
6/21
Variance
interface ReadOnlyList<out x> {
x get(int i);
}
Covariance
More derived type arguments
ReadOnlyList<a> x = new ReadOnlyList<b>(); ✓
a y = x.get(0); ✓
6/21
Variance
Contravariance
Less derived type arguments
WriteOnlyList<b> x = new WriteOnlyList<a>(); ✓
x.add(new b()); ✓
7/21
Variance
interface WriteOnlyList<in x> {
void add(x x);
}
Contravariance
Less derived type arguments
WriteOnlyList<b> x = new WriteOnlyList<a>(); ✓
x.add(new b()); ✓
7/21
Decidability of Subtyping
(Kennedy and Pierce 2007)
Abstract subtyping type system
Undecidable—reduced to PCP
Tractable type system fragments
Restricted subtyping semantics are decidable
How complex are these fragments?
8/21
Types Are Trees
A set of types is a set of trees
• Also called a tree language or a forest
• Defined by a tree grammar
a<b<c>, d>
a
b
c
d
9/21
Tree Grammars
Generalize “word” grammars for trees
Productions are tree/term rewrite rules
Class of tree grammars (regular, context-free, etc.)
Defined by a restriction on the form of productions
10/21
Subtyping Machines
Subtyping programs that recognize tree languages
b : a
c(x) : d(x, x), b
…
Class table
Subtyping
query
11/21
t1 <: t2
Subtyping
machine
(constant) Machine
input
(changing)
Subtyping Machines
Subtyping programs that recognize tree languages
b : a
c(x) : d(x, x), b
…
11/21
t1 <: t2
Subtyping
machine
(constant) Machine
input
(changing)
Subtyping Machines
Subtyping programs that recognize tree languages
b : a
c(x) : d(x, x), b
…
11/21
t1 <: t2
Results
class a<x> : b<a<b<x>>> {}
Expansively recursive inheritance
The expansion of types through inheritance is unlimited
12/21
a<c> → b<a<b<c>>>
Results
class a<x> : b<a<b<x>>> {}
Expansively recursive inheritance
The expansion of types through inheritance is unlimited
12/21
a<c> → b<a<b<c>>> → a<b<c>>
Results
class a<x> : b<a<b<x>>> {}
Expansively recursive inheritance
The expansion of types through inheritance is unlimited
12/21
a<c> → b<a<b<c>>> → a<b<c>> → b<a<b<b<c>>>>
Results
class a<x> : b<a<b<x>>> {}
Expansively recursive inheritance
The expansion of types through inheritance is unlimited
12/21
a<c> → b<a<b<c>>> → a<b<c>> → b<a<b<b<c>>>>
→ a<b<b<c>>>
Results
class a<x> : b<a<b<x>>> {}
Expansively recursive inheritance
The expansion of types through inheritance is unlimited
12/21
a<c> → b<a<b<c>>> → a<b<c>> → b<a<b<b<c>>>>
→ a<b<b<c>>> → … (a<c> → a<b*<c>>)
Results
Non-expansive subtyping is regular
Subtyping machines with non-expansive class tables
recognize regular forests
interface σ<+x> {}
interface v : σ<v> {}
13/21
Results
Example: Cons-lists of Peano numbers
Nat ::= z | s(Nat)
3 s(s(s(z)))
List ::= nil | cons(Nat, List)
[2,1,0] cons(s(s(z)),
cons(s(z),
cons(z,
nil)))
14/21
Results
Example: Cons-lists of Peano numbers
// Grammar terminals
interface z {} interface s<out x> {} interface nil {}
interface cons<out x1, out x2> {}
15/21
Results
Example: Cons-lists of Peano numbers
// Grammar terminals
interface z {} interface s<out x> {} interface nil {}
interface cons<out x1, out x2> {}
// Nat ::= z | s(Nat)
interface Nat : z, s<Nat> {}
// List ::= nil | cons(Nat, List)
interface List : nil, cons<Nat, List> {}
15/21
Results
Example: Cons-lists of Peano numbers
// Grammar terminals
interface z {} interface s<out x> {} interface nil {}
interface cons<out x1, out x2> {}
// Nat ::= z | s(Nat)
interface Nat : z, s<Nat> {}
// List ::= nil | cons(Nat, List)
interface List : nil, cons<Nat, List> {}
// List <: [2,1,0]
cons<s<s<z>>, cons<s<z>, cons<z, nil>>> t = (List) null; ✓
15/21
Results
Non-contravariant subtyping is context-free (GNF)
Subtyping machines without contravariance recognize
context-free forests with grammars in Greibach normal form
interface σ<+x> {}
interface v(x) : σ<τ> {}
16/21
Results
Example: Palindromes
// Grammar terminals
interface a<out x> {} interface b<out x> {} interface E {}
// v0(x) ::= a(v0(a(x))) | a(a(x)) | a(x) | b(v0(b(x))) | …
class v0<x> : a<v0<a<x>>>,a<a<x>>,a<x>,b<v0<b<x>>>,b<b<x>>,b<x> {}
// “abbabba” is a palindrome
a<b<b<a<b<b<a<E>>>>>>> w1 = new v0<E>(); ✓
// “abbabaa” is not a palindrome
a<b<b<a<b<a<a<E>>>>>>> w2 = new v0<E>(); ✗
17/21
Subtyping Metaprogramming
Some APIs have context-free usage protocols
“It is an error to call Restore() more times than
Save() was called.”
- Android’s Canvas API
Canvas ::= Save Canvas Restore Canvas
| Save Canvas
18/21
Subtyping Metaprogramming
Canvas.Draw();
Canvas.Save();
Canvas.Draw();
Canvas.Restore();
Canvas.Restore(); // Runtime exception
Can this exception be detected at compile-time?
19/21
Treetop
• Input: A context-free grammar G describing a domain-specific
language or an API protocol
• Output: A C# fluent API encoding L(G) using a subtyping machine
var shape = Canvas.Draw().Save().Draw().
Restore().Restore().
Done<Canvas>(); ✗ // Subtyping constraint
20/21
In Conclusion
• There is a correspondence between nominal subtyping and
formal forests
• Subtyping machines formalize subtyping computations
• Subtyping metaprogramming?
• Context-free languages can be recognized at compile-time in a
decidable type system fragment
21/21

More Related Content

What's hot

Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
Eelco Visser
 
CS2303 Theory of computation April may 2015
CS2303 Theory of computation April may  2015CS2303 Theory of computation April may  2015
CS2303 Theory of computation April may 2015
appasami
 
STACK Applications in DS
STACK Applications in DSSTACK Applications in DS
STACK Applications in DS
NARESH GUMMAGUTTA
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Sourabh Bhattacharya
 
Cs2303 theory of computation november december 2015
Cs2303 theory of computation november december 2015Cs2303 theory of computation november december 2015
Cs2303 theory of computation november december 2015
appasami
 
Meetup C++ A brief overview of c++17
Meetup C++  A brief overview of c++17Meetup C++  A brief overview of c++17
Meetup C++ A brief overview of c++17
Daniel Eriksson
 
Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programming
izahn
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
Iffat Anjum
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
Johan Tibell
 
8. R Graphics with R
8. R Graphics with R8. R Graphics with R
8. R Graphics with R
FAO
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna university
sangeethajames07
 
COMPILER DESIGN AND CONSTRUCTION
COMPILER DESIGN AND CONSTRUCTIONCOMPILER DESIGN AND CONSTRUCTION
COMPILER DESIGN AND CONSTRUCTION
Anil Pokhrel
 
Cs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papersCs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papers
appasami
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
Basics of objective c
Basics of objective cBasics of objective c
Basics of objective c
sagaroceanic11
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
Pointers
PointersPointers
Pointers
NabishaAK
 
L6
L6L6
L6
lksoo
 
Arrays
ArraysArrays
[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell
Functional Thursday
 

What's hot (20)

Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
CS2303 Theory of computation April may 2015
CS2303 Theory of computation April may  2015CS2303 Theory of computation April may  2015
CS2303 Theory of computation April may 2015
 
STACK Applications in DS
STACK Applications in DSSTACK Applications in DS
STACK Applications in DS
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Cs2303 theory of computation november december 2015
Cs2303 theory of computation november december 2015Cs2303 theory of computation november december 2015
Cs2303 theory of computation november december 2015
 
Meetup C++ A brief overview of c++17
Meetup C++  A brief overview of c++17Meetup C++  A brief overview of c++17
Meetup C++ A brief overview of c++17
 
Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programming
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
High-Performance Haskell
High-Performance HaskellHigh-Performance Haskell
High-Performance Haskell
 
8. R Graphics with R
8. R Graphics with R8. R Graphics with R
8. R Graphics with R
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna university
 
COMPILER DESIGN AND CONSTRUCTION
COMPILER DESIGN AND CONSTRUCTIONCOMPILER DESIGN AND CONSTRUCTION
COMPILER DESIGN AND CONSTRUCTION
 
Cs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papersCs2303 theory of computation all anna University question papers
Cs2303 theory of computation all anna University question papers
 
C programming - String
C programming - StringC programming - String
C programming - String
 
Basics of objective c
Basics of objective cBasics of objective c
Basics of objective c
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
Pointers
PointersPointers
Pointers
 
L6
L6L6
L6
 
Arrays
ArraysArrays
Arrays
 
[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell
 

Similar to Study of the Subtyping Machine of Nominal Subtyping with Variance

Introduction to R
Introduction to RIntroduction to R
Introduction to R
Samuel Bosch
 
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experienceJAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
jazoon13
 
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
openCypher
 
"That scripting language called Prolog"
"That scripting language called Prolog""That scripting language called Prolog"
"That scripting language called Prolog"
Sergei Winitzki
 
Scala Collections : Java 8 on Steroids
Scala Collections : Java 8 on SteroidsScala Collections : Java 8 on Steroids
Scala Collections : Java 8 on Steroids
François Garillot
 
Generic Functional Programming with Type Classes
Generic Functional Programming with Type ClassesGeneric Functional Programming with Type Classes
Generic Functional Programming with Type Classes
Tapio Rautonen
 
Gate-Cs 1996
Gate-Cs 1996Gate-Cs 1996
Gate-Cs 1996
Ravi Rajput
 
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow AnalysisDetecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Silvio Cesare
 
Variational autoencoders for speech processing d.bielievtsov dataconf 21 04 18
Variational autoencoders for speech processing d.bielievtsov dataconf 21 04 18Variational autoencoders for speech processing d.bielievtsov dataconf 21 04 18
Variational autoencoders for speech processing d.bielievtsov dataconf 21 04 18
Olga Zinkevych
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
Eelco Visser
 
Finding similar items in high dimensional spaces locality sensitive hashing
Finding similar items in high dimensional spaces  locality sensitive hashingFinding similar items in high dimensional spaces  locality sensitive hashing
Finding similar items in high dimensional spaces locality sensitive hashing
Dmitriy Selivanov
 
Дмитрий Селиванов, OK.RU. Finding Similar Items in high-dimensional spaces: L...
Дмитрий Селиванов, OK.RU. Finding Similar Items in high-dimensional spaces: L...Дмитрий Селиванов, OK.RU. Finding Similar Items in high-dimensional spaces: L...
Дмитрий Селиванов, OK.RU. Finding Similar Items in high-dimensional spaces: L...
Mail.ru Group
 
Decision Trees and Bayes Classifiers
Decision Trees and Bayes ClassifiersDecision Trees and Bayes Classifiers
Decision Trees and Bayes Classifiers
Alexander Jung
 
Introduction to Deep Generative Models
Introduction to Deep Generative ModelsIntroduction to Deep Generative Models
Introduction to Deep Generative Models
Hao-Wen (Herman) Dong
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
Khaled Al-Shamaa
 
TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...
TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...
TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...
Iosif Itkin
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...
Piotr Paradziński
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...
Scalac
 
Dependent dynamic rules
Dependent dynamic rulesDependent dynamic rules
Dependent dynamic rules
Eelco Visser
 
Ch4.mapreduce algorithm design
Ch4.mapreduce algorithm designCh4.mapreduce algorithm design
Ch4.mapreduce algorithm design
AllenWu
 

Similar to Study of the Subtyping Machine of Nominal Subtyping with Variance (20)

Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experienceJAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
JAZOON'13 - Paul Brauner - A backend developer meets the web: my Dart experience
 
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
 
"That scripting language called Prolog"
"That scripting language called Prolog""That scripting language called Prolog"
"That scripting language called Prolog"
 
Scala Collections : Java 8 on Steroids
Scala Collections : Java 8 on SteroidsScala Collections : Java 8 on Steroids
Scala Collections : Java 8 on Steroids
 
Generic Functional Programming with Type Classes
Generic Functional Programming with Type ClassesGeneric Functional Programming with Type Classes
Generic Functional Programming with Type Classes
 
Gate-Cs 1996
Gate-Cs 1996Gate-Cs 1996
Gate-Cs 1996
 
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow AnalysisDetecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
 
Variational autoencoders for speech processing d.bielievtsov dataconf 21 04 18
Variational autoencoders for speech processing d.bielievtsov dataconf 21 04 18Variational autoencoders for speech processing d.bielievtsov dataconf 21 04 18
Variational autoencoders for speech processing d.bielievtsov dataconf 21 04 18
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
 
Finding similar items in high dimensional spaces locality sensitive hashing
Finding similar items in high dimensional spaces  locality sensitive hashingFinding similar items in high dimensional spaces  locality sensitive hashing
Finding similar items in high dimensional spaces locality sensitive hashing
 
Дмитрий Селиванов, OK.RU. Finding Similar Items in high-dimensional spaces: L...
Дмитрий Селиванов, OK.RU. Finding Similar Items in high-dimensional spaces: L...Дмитрий Селиванов, OK.RU. Finding Similar Items in high-dimensional spaces: L...
Дмитрий Селиванов, OK.RU. Finding Similar Items in high-dimensional spaces: L...
 
Decision Trees and Bayes Classifiers
Decision Trees and Bayes ClassifiersDecision Trees and Bayes Classifiers
Decision Trees and Bayes Classifiers
 
Introduction to Deep Generative Models
Introduction to Deep Generative ModelsIntroduction to Deep Generative Models
Introduction to Deep Generative Models
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...
TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...
TMPA-2017: Functional Parser of Markdown Language Based on Monad Combining an...
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...
 
Dependent dynamic rules
Dependent dynamic rulesDependent dynamic rules
Dependent dynamic rules
 
Ch4.mapreduce algorithm design
Ch4.mapreduce algorithm designCh4.mapreduce algorithm design
Ch4.mapreduce algorithm design
 

Recently uploaded

Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdfMending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
Selcen Ozturkcan
 
EWOCS-I: The catalog of X-ray sources in Westerlund 1 from the Extended Weste...
EWOCS-I: The catalog of X-ray sources in Westerlund 1 from the Extended Weste...EWOCS-I: The catalog of X-ray sources in Westerlund 1 from the Extended Weste...
EWOCS-I: The catalog of X-ray sources in Westerlund 1 from the Extended Weste...
Sérgio Sacani
 
Methods of grain storage Structures in India.pdf
Methods of grain storage Structures in India.pdfMethods of grain storage Structures in India.pdf
Methods of grain storage Structures in India.pdf
PirithiRaju
 
Compexometric titration/Chelatorphy titration/chelating titration
Compexometric titration/Chelatorphy titration/chelating titrationCompexometric titration/Chelatorphy titration/chelating titration
Compexometric titration/Chelatorphy titration/chelating titration
Vandana Devesh Sharma
 
在线办理(salfor毕业证书)索尔福德大学毕业证毕业完成信一模一样
在线办理(salfor毕业证书)索尔福德大学毕业证毕业完成信一模一样在线办理(salfor毕业证书)索尔福德大学毕业证毕业完成信一模一样
在线办理(salfor毕业证书)索尔福德大学毕业证毕业完成信一模一样
vluwdy49
 
cathode ray oscilloscope and its applications
cathode ray oscilloscope and its applicationscathode ray oscilloscope and its applications
cathode ray oscilloscope and its applications
sandertein
 
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
hozt8xgk
 
Pests of Storage_Identification_Dr.UPR.pdf
Pests of Storage_Identification_Dr.UPR.pdfPests of Storage_Identification_Dr.UPR.pdf
Pests of Storage_Identification_Dr.UPR.pdf
PirithiRaju
 
HOW DO ORGANISMS REPRODUCE?reproduction part 1
HOW DO ORGANISMS REPRODUCE?reproduction part 1HOW DO ORGANISMS REPRODUCE?reproduction part 1
HOW DO ORGANISMS REPRODUCE?reproduction part 1
Shashank Shekhar Pandey
 
Discovery of An Apparent Red, High-Velocity Type Ia Supernova at 𝐳 = 2.9 wi...
Discovery of An Apparent Red, High-Velocity Type Ia Supernova at  𝐳 = 2.9  wi...Discovery of An Apparent Red, High-Velocity Type Ia Supernova at  𝐳 = 2.9  wi...
Discovery of An Apparent Red, High-Velocity Type Ia Supernova at 𝐳 = 2.9 wi...
Sérgio Sacani
 
Randomised Optimisation Algorithms in DAPHNE
Randomised Optimisation Algorithms in DAPHNERandomised Optimisation Algorithms in DAPHNE
Randomised Optimisation Algorithms in DAPHNE
University of Maribor
 
Sciences of Europe journal No 142 (2024)
Sciences of Europe journal No 142 (2024)Sciences of Europe journal No 142 (2024)
Sciences of Europe journal No 142 (2024)
Sciences of Europe
 
Alternate Wetting and Drying - Climate Smart Agriculture
Alternate Wetting and Drying - Climate Smart AgricultureAlternate Wetting and Drying - Climate Smart Agriculture
Alternate Wetting and Drying - Climate Smart Agriculture
International Food Policy Research Institute- South Asia Office
 
Authoring a personal GPT for your research and practice: How we created the Q...
Authoring a personal GPT for your research and practice: How we created the Q...Authoring a personal GPT for your research and practice: How we created the Q...
Authoring a personal GPT for your research and practice: How we created the Q...
Leonel Morgado
 
Sexuality - Issues, Attitude and Behaviour - Applied Social Psychology - Psyc...
Sexuality - Issues, Attitude and Behaviour - Applied Social Psychology - Psyc...Sexuality - Issues, Attitude and Behaviour - Applied Social Psychology - Psyc...
Sexuality - Issues, Attitude and Behaviour - Applied Social Psychology - Psyc...
PsychoTech Services
 
Evidence of Jet Activity from the Secondary Black Hole in the OJ 287 Binary S...
Evidence of Jet Activity from the Secondary Black Hole in the OJ 287 Binary S...Evidence of Jet Activity from the Secondary Black Hole in the OJ 287 Binary S...
Evidence of Jet Activity from the Secondary Black Hole in the OJ 287 Binary S...
Sérgio Sacani
 
23PH301 - Optics - Optical Lenses.pptx
23PH301 - Optics  -  Optical Lenses.pptx23PH301 - Optics  -  Optical Lenses.pptx
23PH301 - Optics - Optical Lenses.pptx
RDhivya6
 
Microbiology of Central Nervous System INFECTIONS.pdf
Microbiology of Central Nervous System INFECTIONS.pdfMicrobiology of Central Nervous System INFECTIONS.pdf
Microbiology of Central Nervous System INFECTIONS.pdf
sammy700571
 
Travis Hills of MN is Making Clean Water Accessible to All Through High Flux ...
Travis Hills of MN is Making Clean Water Accessible to All Through High Flux ...Travis Hills of MN is Making Clean Water Accessible to All Through High Flux ...
Travis Hills of MN is Making Clean Water Accessible to All Through High Flux ...
Travis Hills MN
 
CLASS 12th CHEMISTRY SOLID STATE ppt (Animated)
CLASS 12th CHEMISTRY SOLID STATE ppt (Animated)CLASS 12th CHEMISTRY SOLID STATE ppt (Animated)
CLASS 12th CHEMISTRY SOLID STATE ppt (Animated)
eitps1506
 

Recently uploaded (20)

Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdfMending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
 
EWOCS-I: The catalog of X-ray sources in Westerlund 1 from the Extended Weste...
EWOCS-I: The catalog of X-ray sources in Westerlund 1 from the Extended Weste...EWOCS-I: The catalog of X-ray sources in Westerlund 1 from the Extended Weste...
EWOCS-I: The catalog of X-ray sources in Westerlund 1 from the Extended Weste...
 
Methods of grain storage Structures in India.pdf
Methods of grain storage Structures in India.pdfMethods of grain storage Structures in India.pdf
Methods of grain storage Structures in India.pdf
 
Compexometric titration/Chelatorphy titration/chelating titration
Compexometric titration/Chelatorphy titration/chelating titrationCompexometric titration/Chelatorphy titration/chelating titration
Compexometric titration/Chelatorphy titration/chelating titration
 
在线办理(salfor毕业证书)索尔福德大学毕业证毕业完成信一模一样
在线办理(salfor毕业证书)索尔福德大学毕业证毕业完成信一模一样在线办理(salfor毕业证书)索尔福德大学毕业证毕业完成信一模一样
在线办理(salfor毕业证书)索尔福德大学毕业证毕业完成信一模一样
 
cathode ray oscilloscope and its applications
cathode ray oscilloscope and its applicationscathode ray oscilloscope and its applications
cathode ray oscilloscope and its applications
 
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
 
Pests of Storage_Identification_Dr.UPR.pdf
Pests of Storage_Identification_Dr.UPR.pdfPests of Storage_Identification_Dr.UPR.pdf
Pests of Storage_Identification_Dr.UPR.pdf
 
HOW DO ORGANISMS REPRODUCE?reproduction part 1
HOW DO ORGANISMS REPRODUCE?reproduction part 1HOW DO ORGANISMS REPRODUCE?reproduction part 1
HOW DO ORGANISMS REPRODUCE?reproduction part 1
 
Discovery of An Apparent Red, High-Velocity Type Ia Supernova at 𝐳 = 2.9 wi...
Discovery of An Apparent Red, High-Velocity Type Ia Supernova at  𝐳 = 2.9  wi...Discovery of An Apparent Red, High-Velocity Type Ia Supernova at  𝐳 = 2.9  wi...
Discovery of An Apparent Red, High-Velocity Type Ia Supernova at 𝐳 = 2.9 wi...
 
Randomised Optimisation Algorithms in DAPHNE
Randomised Optimisation Algorithms in DAPHNERandomised Optimisation Algorithms in DAPHNE
Randomised Optimisation Algorithms in DAPHNE
 
Sciences of Europe journal No 142 (2024)
Sciences of Europe journal No 142 (2024)Sciences of Europe journal No 142 (2024)
Sciences of Europe journal No 142 (2024)
 
Alternate Wetting and Drying - Climate Smart Agriculture
Alternate Wetting and Drying - Climate Smart AgricultureAlternate Wetting and Drying - Climate Smart Agriculture
Alternate Wetting and Drying - Climate Smart Agriculture
 
Authoring a personal GPT for your research and practice: How we created the Q...
Authoring a personal GPT for your research and practice: How we created the Q...Authoring a personal GPT for your research and practice: How we created the Q...
Authoring a personal GPT for your research and practice: How we created the Q...
 
Sexuality - Issues, Attitude and Behaviour - Applied Social Psychology - Psyc...
Sexuality - Issues, Attitude and Behaviour - Applied Social Psychology - Psyc...Sexuality - Issues, Attitude and Behaviour - Applied Social Psychology - Psyc...
Sexuality - Issues, Attitude and Behaviour - Applied Social Psychology - Psyc...
 
Evidence of Jet Activity from the Secondary Black Hole in the OJ 287 Binary S...
Evidence of Jet Activity from the Secondary Black Hole in the OJ 287 Binary S...Evidence of Jet Activity from the Secondary Black Hole in the OJ 287 Binary S...
Evidence of Jet Activity from the Secondary Black Hole in the OJ 287 Binary S...
 
23PH301 - Optics - Optical Lenses.pptx
23PH301 - Optics  -  Optical Lenses.pptx23PH301 - Optics  -  Optical Lenses.pptx
23PH301 - Optics - Optical Lenses.pptx
 
Microbiology of Central Nervous System INFECTIONS.pdf
Microbiology of Central Nervous System INFECTIONS.pdfMicrobiology of Central Nervous System INFECTIONS.pdf
Microbiology of Central Nervous System INFECTIONS.pdf
 
Travis Hills of MN is Making Clean Water Accessible to All Through High Flux ...
Travis Hills of MN is Making Clean Water Accessible to All Through High Flux ...Travis Hills of MN is Making Clean Water Accessible to All Through High Flux ...
Travis Hills of MN is Making Clean Water Accessible to All Through High Flux ...
 
CLASS 12th CHEMISTRY SOLID STATE ppt (Animated)
CLASS 12th CHEMISTRY SOLID STATE ppt (Animated)CLASS 12th CHEMISTRY SOLID STATE ppt (Animated)
CLASS 12th CHEMISTRY SOLID STATE ppt (Animated)
 

Study of the Subtyping Machine of Nominal Subtyping with Variance

  • 2. Overview Goal Investigate the connection between subtyping and tree languages Method Formalize the computability of subtyping with the subtyping machine 2/21
  • 3. Subtyping Scope Declaration-site nominal subtyping with variance (Kennedy and Pierce 2007) What is subtyping? A type system decision problem t1 <: t2 3/21
  • 4. Subtyping class b : a {} a x = new b(); ✓ // b <: a x = new Set(); ✗ Subtyping is everywhere • Variable assignments • Method arguments 4/21
  • 5. Subtyping Subtyping with type parameters Collection<b> x = new List<b>(); ✓ List<a> list_b = new List<b>(); ??? 5/21
  • 6. Subtyping Subtyping with type parameters Collection<b> x = new List<b>(); ✓ List<a> list_b = new List<b>(); ✗ list_b.add(new a()); ✗ 5/21
  • 7. Subtyping Subtyping with type parameters Collection<b> x = new List<b>(); ✓ List<a> list_b = new List<b>(); ✗ list_b.add(new a()); ✗ 5/21 List<b> list_a = new List<a>(); ✗ b y = list_a.get(0); ✗
  • 8. Variance Covariance More derived type arguments ReadOnlyList<a> x = new ReadOnlyList<b>(); ✓ a y = x.get(0); ✓ 6/21
  • 9. Variance interface ReadOnlyList<out x> { x get(int i); } Covariance More derived type arguments ReadOnlyList<a> x = new ReadOnlyList<b>(); ✓ a y = x.get(0); ✓ 6/21
  • 10. Variance Contravariance Less derived type arguments WriteOnlyList<b> x = new WriteOnlyList<a>(); ✓ x.add(new b()); ✓ 7/21
  • 11. Variance interface WriteOnlyList<in x> { void add(x x); } Contravariance Less derived type arguments WriteOnlyList<b> x = new WriteOnlyList<a>(); ✓ x.add(new b()); ✓ 7/21
  • 12. Decidability of Subtyping (Kennedy and Pierce 2007) Abstract subtyping type system Undecidable—reduced to PCP Tractable type system fragments Restricted subtyping semantics are decidable How complex are these fragments? 8/21
  • 13. Types Are Trees A set of types is a set of trees • Also called a tree language or a forest • Defined by a tree grammar a<b<c>, d> a b c d 9/21
  • 14. Tree Grammars Generalize “word” grammars for trees Productions are tree/term rewrite rules Class of tree grammars (regular, context-free, etc.) Defined by a restriction on the form of productions 10/21
  • 15. Subtyping Machines Subtyping programs that recognize tree languages b : a c(x) : d(x, x), b … Class table Subtyping query 11/21 t1 <: t2
  • 16. Subtyping machine (constant) Machine input (changing) Subtyping Machines Subtyping programs that recognize tree languages b : a c(x) : d(x, x), b … 11/21 t1 <: t2
  • 17. Subtyping machine (constant) Machine input (changing) Subtyping Machines Subtyping programs that recognize tree languages b : a c(x) : d(x, x), b … 11/21 t1 <: t2
  • 18. Results class a<x> : b<a<b<x>>> {} Expansively recursive inheritance The expansion of types through inheritance is unlimited 12/21 a<c> → b<a<b<c>>>
  • 19. Results class a<x> : b<a<b<x>>> {} Expansively recursive inheritance The expansion of types through inheritance is unlimited 12/21 a<c> → b<a<b<c>>> → a<b<c>>
  • 20. Results class a<x> : b<a<b<x>>> {} Expansively recursive inheritance The expansion of types through inheritance is unlimited 12/21 a<c> → b<a<b<c>>> → a<b<c>> → b<a<b<b<c>>>>
  • 21. Results class a<x> : b<a<b<x>>> {} Expansively recursive inheritance The expansion of types through inheritance is unlimited 12/21 a<c> → b<a<b<c>>> → a<b<c>> → b<a<b<b<c>>>> → a<b<b<c>>>
  • 22. Results class a<x> : b<a<b<x>>> {} Expansively recursive inheritance The expansion of types through inheritance is unlimited 12/21 a<c> → b<a<b<c>>> → a<b<c>> → b<a<b<b<c>>>> → a<b<b<c>>> → … (a<c> → a<b*<c>>)
  • 23. Results Non-expansive subtyping is regular Subtyping machines with non-expansive class tables recognize regular forests interface σ<+x> {} interface v : σ<v> {} 13/21
  • 24. Results Example: Cons-lists of Peano numbers Nat ::= z | s(Nat) 3 s(s(s(z))) List ::= nil | cons(Nat, List) [2,1,0] cons(s(s(z)), cons(s(z), cons(z, nil))) 14/21
  • 25. Results Example: Cons-lists of Peano numbers // Grammar terminals interface z {} interface s<out x> {} interface nil {} interface cons<out x1, out x2> {} 15/21
  • 26. Results Example: Cons-lists of Peano numbers // Grammar terminals interface z {} interface s<out x> {} interface nil {} interface cons<out x1, out x2> {} // Nat ::= z | s(Nat) interface Nat : z, s<Nat> {} // List ::= nil | cons(Nat, List) interface List : nil, cons<Nat, List> {} 15/21
  • 27. Results Example: Cons-lists of Peano numbers // Grammar terminals interface z {} interface s<out x> {} interface nil {} interface cons<out x1, out x2> {} // Nat ::= z | s(Nat) interface Nat : z, s<Nat> {} // List ::= nil | cons(Nat, List) interface List : nil, cons<Nat, List> {} // List <: [2,1,0] cons<s<s<z>>, cons<s<z>, cons<z, nil>>> t = (List) null; ✓ 15/21
  • 28. Results Non-contravariant subtyping is context-free (GNF) Subtyping machines without contravariance recognize context-free forests with grammars in Greibach normal form interface σ<+x> {} interface v(x) : σ<τ> {} 16/21
  • 29. Results Example: Palindromes // Grammar terminals interface a<out x> {} interface b<out x> {} interface E {} // v0(x) ::= a(v0(a(x))) | a(a(x)) | a(x) | b(v0(b(x))) | … class v0<x> : a<v0<a<x>>>,a<a<x>>,a<x>,b<v0<b<x>>>,b<b<x>>,b<x> {} // “abbabba” is a palindrome a<b<b<a<b<b<a<E>>>>>>> w1 = new v0<E>(); ✓ // “abbabaa” is not a palindrome a<b<b<a<b<a<a<E>>>>>>> w2 = new v0<E>(); ✗ 17/21
  • 30. Subtyping Metaprogramming Some APIs have context-free usage protocols “It is an error to call Restore() more times than Save() was called.” - Android’s Canvas API Canvas ::= Save Canvas Restore Canvas | Save Canvas 18/21
  • 31. Subtyping Metaprogramming Canvas.Draw(); Canvas.Save(); Canvas.Draw(); Canvas.Restore(); Canvas.Restore(); // Runtime exception Can this exception be detected at compile-time? 19/21
  • 32. Treetop • Input: A context-free grammar G describing a domain-specific language or an API protocol • Output: A C# fluent API encoding L(G) using a subtyping machine var shape = Canvas.Draw().Save().Draw(). Restore().Restore(). Done<Canvas>(); ✗ // Subtyping constraint 20/21
  • 33. In Conclusion • There is a correspondence between nominal subtyping and formal forests • Subtyping machines formalize subtyping computations • Subtyping metaprogramming? • Context-free languages can be recognized at compile-time in a decidable type system fragment 21/21