Semantic Subtyping. Alain Frisch (ENS Paris) Giuseppe Castagna (ENS Paris) Véronique Benzaken (LRI U Paris Sud)

Similar documents
Recognizing regular tree languages with static information

REGULAR TREE LANGUAGE RECOGNITION WITH STATIC INFORMATION

An update on XML types

Programming Languages for XML Ou Au delà des standards

Greedy regular expression matching

Semantic Subtyping for Objects and Classes

Type-based Optimization for Regular Patterns

Subsumption. Principle of safe substitution

CDuce. Véronique Benzaken, Giuseppe Castagna, Alain Frisch. PSD Workshop,

Formal Systems and their Applications

Part III. Chapter 15: Subtyping

Part III Chapter 15: Subtyping

Semantic Subtyping for Objects and Classes

Copyright 2013 IFIP International Federation for Information Processing

Semantic subtyping: challenges, perspectives, and open problems

A Typed Lambda Calculus for Input Sanitation

Advances in Programming Languages

Programming Languages Lecture 15: Recursive Types & Subtyping

Type Systems. Pierce Ch. 3, 8, 11, 15 CSE

Chapter 3: Propositional Languages

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

LTCS Report. Concept Descriptions with Set Constraints and Cardinality Constraints. Franz Baader. LTCS-Report 17-02

CS 6110 S14 Lecture 1 Introduction 24 January 2014

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

Polymorphism and XDuce-style patterns

Timed Automata: Semantics, Algorithms and Tools

Lecture Notes on Program Equivalence

Subtyping. Lecture 13 CS 565 3/27/06

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Distributed Systems Programming (F21DS1) Formal Verification

Formal languages and computation models

Foundations of AI. 9. Predicate Logic. Syntax and Semantics, Normal Forms, Herbrand Expansion, Resolution

Lecture 2. Decidability and Verification

CS558 Programming Languages

Dependent Object Types - A foundation for Scala s type system

The three faces of homotopy type theory. Type theory and category theory. Minicourse plan. Typing judgments. Michael Shulman.

COS 320. Compiling Techniques

A Coalgebraic Foundation for Coinductive Union Types

Lecture Notes on Aggregate Data Structures

Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters. Corky Cartwright January 26, 2018

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

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

Operational Semantics. One-Slide Summary. Lecture Outline

Recursive Types and Subtyping

Principles of Program Analysis: A Sampler of Approaches

CS558 Programming Languages

Variables. Substitution

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

Programming Languages Lecture 14: Sum, Product, Recursive Types

Verification Overview Testing Theory and Principles Testing in Practice. Verification. Miaoqing Huang University of Arkansas 1 / 80

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Harvard School of Engineering and Applied Sciences Computer Science 152

Introduction to Homotopy Type Theory

CSE-321 Programming Languages 2014 Final

Programming Languages

PROPAGATION-BASED CONSTRAINT SOLVER IN IMS Igor Ol. Blynov Kherson State University

From Tableaux to Automata for Description Logics

Automatic synthesis of switching controllers for linear hybrid systems: Reachability control

Propositional Logic. Part I

Lecture 1: Conjunctive Queries

Polymorphic Functions with Set-Theoretic Types

Programming Languages Third Edition

A Core Calculus for XQuery 3.0

Computing least common subsumers for FLE +

Type Based XML Projection

Constrained Types and their Expressiveness

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS

Fundamental Concepts. Chapter 1

A Modality for Recursion

Lecture 7. Search. Search. Foundations of Constraint Programming

15.4 Longest common subsequence

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

Towards a Memory-Efficient Knapsack DP Algorithm

The design of a programming language for provably correct programs: success and failure

EXTENSIONS OF FIRST ORDER LOGIC

Operational Semantics

Types for References, Exceptions and Continuations. Review of Subtyping. Γ e:τ τ <:σ Γ e:σ. Annoucements. How s the midterm going?

Principles of Programming Languages

Mutable References. Chapter 1

3.7 Denotational Semantics

1 Introduction. 3 Syntax

Fiona A Tool to Analyze Interacting Open Nets

Semantic Subtyping for Objects and Classes

Multi Domain Logic and its Applications to SAT

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Critical Analysis of Computer Science Methodology: Theory

nfn2dlp: A Normal Form Nested Programs Compiler

Categorical models of type theory

Semantic Subtyping with an SMT Solver

Derivation for the Necessity of Recursive Types and its Basic Usage

Typed Lambda Calculus. Chapter 9 Benjamin Pierce Types and Programming Languages

CSC 501 Semantics of Programming Languages

Overview. A normal-order language. Strictness. Recursion. Infinite data structures. Direct denotational semantics. Transition semantics

Verifying pattern matching with guards in Scala

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,

1. Lexical Analysis Phase

Discrete Mathematics Lecture 4. Harper Langston New York University

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

Principles of Programming Languages

Recursive Types and Subtyping

Transcription:

Semantic Subtyping Alain Frisch (ENS Paris) Giuseppe Castagna (ENS Paris) Véronique Benzaken (LRI U Paris Sud) http://www.cduce.org/ Semantic Subtyping - Groupe de travail BD LRI p.1/28

CDuce A functional language adapted to XML applications: http://www.cduce.org/ Types are pervasives in Duce: Soundness of transformations Informative error messages Type-driven semantics, pattern matching Type-driven compilation and optimization This talk: theoretical foundation of Duce type system. Most of the technical difficulties in the subtyping relation, which is kept simple by using a semantic approach. Semantic Subtyping - Groupe de travail BD LRI p.2/28

Semantic and syntactic subtyping How to define a subtyping relation? Syntactic approach: a formal system (axioms,rules) Semantic approach: start with a denotational model of the language interpret types as subsets of the model define subtyping as inclusion of denotations derive a subtyping algorithm Semantic Subtyping - Groupe de travail BD LRI p.3/28

Advantages of semantic subtyping subtyping is complete w.r.t the intuitive interpretation when does not hold, it is possible to exhibit an element of the model in the interpretation of and not of ( error message) modularization of proofs: use the semantic interpretation, not the rules of the subtyping algorithm properties for free : transitivity of,... Whenever possible, avoid ad hoc rules, formulas and algorithms: derive them from computations. Semantic Subtyping - Groupe de travail BD LRI p.4/28

XDuce (H. Hosoya, B. Pierce, J. Vouillon) XDuce: a typed programming language for XML applications value = XML document (tree) type = regular tree language subtyping = inclusion of languages A powerful pattern-matching operation Type-driven semantics Recursive patterns to extract information in the middle of a document Exact propagation of the type from the matched expression to binding variables Semantic Subtyping - Groupe de travail BD LRI p.5/28

Semantic subtyping in XDuce Semantic subtyping: easy because no first class function, so typing of values does not depend on subtyping! Start from the typing judgment Interpretation Subtyping Semantic Subtyping - Groupe de travail BD LRI p.6/28

XDuce + higher-order Duce Integrate XDuce features to a general higher order functional language Extend XDuce semantic approach? But: typing of values now depends on subtyping! Classical semantic approach? Define an untyped denotational model But: semantics depends on typing! Semantic Subtyping - Groupe de travail BD LRI p.7/28

Circularities Type system PM on types Subtyping Typing values PM semantics Semantic Subtyping - Groupe de travail BD LRI p.8/28

Circularities Type system PM on types Subtyping Typing values PM semantics Model Semantic Subtyping - Groupe de travail BD LRI p.8/28

Circularities Type system PM on types Subtyping Typing values PM semantics Model Semantic Subtyping - Groupe de travail BD LRI p.8/28

Circularities Type system PM on types Subtyping Typing values PM semantics Model Semantic Subtyping - Groupe de travail BD LRI p.8/28

Types Semantic Subtyping - Groupe de travail BD LRI p.9/28

Type algebra Types: Constructors: basic, product, arrow types. Semantic Subtyping - Groupe de travail BD LRI p.10/28

Type algebra Types: Constructors: basic, product, arrow types. Arbitrary finite boolean combinations. Semantic Subtyping - Groupe de travail BD LRI p.10/28

Type algebra Types: Constructors: basic, product, arrow types. Arbitrary finite boolean combinations. Guarded recursive types. Semantic Subtyping - Groupe de travail BD LRI p.10/28

Subtyping and models by: We want to define : is subset of a structure For each type, prod fun with: basic prod must satisfy natural conditions: _ The interpretation function prod Semantic Subtyping - Groupe de travail BD LRI p.11/28

Model condition for arrows A condition on motivated by: Intuition: extensive view of functions (=binary relations) Derived from simple set-theoretic computations Makes the safety proof work The type system induces a model of values (Turns out to hold in the revelance logic B+; M. Dezani) Semantic Subtyping - Groupe de travail BD LRI p.12/28

Is there at least one model!? Yes, this one: basic It is universal (largest subtyping relation). For this model, we derive an algorithm to compute. Semantic Subtyping - Groupe de travail BD LRI p.13/28

The language Semantic Subtyping - Groupe de travail BD LRI p.14/28

The language: syntax variable abstraction application constant pair pattern matching... Semantic Subtyping - Groupe de travail BD LRI p.15/28

Type system Semantic Subtyping - Groupe de travail BD LRI p.16/28...

Type system with... Need it for subject reduction...... but can discard it for typechecking. Semantic Subtyping - Groupe de travail BD LRI p.16/28

Results Classical syntactical results, such as admissibility of conjunction rule and subsumption elimination. Subject reduction for a small step semantics. A new interpretation of types as sets of values: This is indeed a model. It induces the same subtyping relation as the bootstrap model. This holds because of overloaded functions! Semantic Subtyping - Groupe de travail BD LRI p.17/28

The circle is now complete ) ( Semantic Subtyping - Groupe de travail BD LRI p.18/28

Subtyping algorithm As any coinductive relation, the subtyping algorithm can be expressed in an abstract way through a notion of simulation. A simulation is a subset of all types closed under rules like: The largest simulation is exactly the set of empty types. This abstract presentation separates implementation issues (such as caching) and the theoretical study of the algorithm. Semantic Subtyping - Groupe de travail BD LRI p.19/28

Using set-theoretic semantics Simple set-theoretic facts yield a number of optimizations for the subtyping algorithm, avoiding exponential explosion in many cases. E.g.: whenever Semantic Subtyping - Groupe de travail BD LRI p.20/28

Patterns Semantic Subtyping - Groupe de travail BD LRI p.21/28

Patterns capture type constraint conjunction alternative pair constant recursive pattern Result of matching : (failure) or a substitution Var. Semantic Subtyping - Groupe de travail BD LRI p.22/28

Pattern-matching: static semantics The pattern accepts a type characterized by: If by: Thm: it exists + algorithm and Var, type of the result for characterized Thm: it exists + algorithm Semantic Subtyping - Groupe de travail BD LRI p.23/28

Type system: pattern matching ) ( Semantic Subtyping - Groupe de travail BD LRI p.24/28

Type system: pattern matching ) ( Exhaustivity checking : set of values matched by Semantic Subtyping - Groupe de travail BD LRI p.24/28

Type system: pattern matching ) ( Exhaustivity checking : set of values matched by Dispatching Semantic Subtyping - Groupe de travail BD LRI p.24/28

Type system: pattern matching ) ( Exhaustivity checking : set of values matched by Dispatching Matching : typing environment for variables bound in Semantic Subtyping - Groupe de travail BD LRI p.24/28

Type system: pattern matching ) ( Exhaustivity checking : set of values matched by Dispatching Matching : typing environment for variables bound in Result Discard useless branches Semantic Subtyping - Groupe de travail BD LRI p.24/28

Typing patterns: an example Lists à la Lisp (head,tail) + terminator. Consider the following pattern and types: : If Otherwise: Then: If : Semantic Subtyping - Groupe de travail BD LRI p.25/28

Pattern algorithms (1) Semantic Subtyping - Groupe de travail BD LRI p.26/28

Pattern algorithms (2) Var if Var Var if Var Var if Var Var if if if Semantic Subtyping - Groupe de travail BD LRI p.27/28

Compiling pattern matching Naive solution: backtracking. Less naive, but untractable: bottom-up tree automata. Adopted solution: hybrid top-down/bottom-up automata, which avoid backtracking, and take profit of static type information. Complex algorithm: set-theoretic semantics of types and patterns helps a lot here! Semantic Subtyping - Groupe de travail BD LRI p.28/28