Linear Types for Continuations



Similar documents
Linearly Used Effects: Monadic and CPS Transformations into the Linear Lambda Calculus

Parametric Domain-theoretic models of Linear Abadi & Plotkin Logic

Direct models of the computational lambda-calculus

FUNCTIONAL ANALYSIS LECTURE NOTES: QUOTIENT SPACES

Notions of computation and monads

Coeffects: Unified static analysis of context-dependence

Non-deterministic Semantics and the Undecidability of Boolean BI

A Note on Context Logic

Section IV.21. The Field of Quotients of an Integral Domain

How To Prove The Dirichlet Unit Theorem

Observational Program Calculi and the Correctness of Translations

NOTES ON CATEGORIES AND FUNCTORS

Complete Axioms for Categorical Fixed-point Operators

Semantics and Verification of Software

Summary Last Lecture. Automated Reasoning. Outline of the Lecture. Definition sequent calculus. Theorem (Normalisation and Strong Normalisation)

Chapter 7: Functional Programming Languages

CHAPTER 7 GENERAL PROOF SYSTEMS

Left-Handed Completeness

Andrew Pitts chapter for D. Sangorgi and J. Rutten (eds), Advanced Topics in Bisimulation and Coinduction, Cambridge Tracts in Theoretical Computer

Modal Proofs as Distributed Programs (Extended Abstract)

Degrees of Truth: the formal logic of classical and quantum probabilities as well as fuzzy sets.

Bindings, mobility of bindings, and the -quantifier

Ideal Class Group and Units

Research Note. Bi-intuitionistic Boolean Bunched Logic

Mathematics Course 111: Algebra I Part IV: Vector Spaces

Categorical Monads and Computer Programming

ON UNIQUE FACTORIZATION DOMAINS

Call-by-Value is Dual to Call-by-Name

INTRODUCTORY SET THEORY

Section 1.4. Lines, Planes, and Hyperplanes. The Calculus of Functions of Several Variables

ADJUNCTION MODELS FOR CALL-BY-PUSH-VALUE WITH STACKS

Verifying security protocols using theorem provers

GROUP ALGEBRAS. ANDREI YAFAEV

ORIENTATIONS. Contents

Blame for All. Jeremy G. Siek. Amal Ahmed. Robert Bruce Findler. Philip Wadler. Abstract. 1. Introduction

Simulation-Based Security with Inexhaustible Interactive Turing Machines

A Propositional Dynamic Logic for CCS Programs

Notes from February 11

Properties of Real Numbers

Introduction to Type Theory

ISOMETRIES OF R n KEITH CONRAD

Introduction to Algebraic Geometry. Bézout s Theorem and Inflection Points

ABSTRACT ALGEBRA: A STUDY GUIDE FOR BEGINNERS

Linear Algebra Notes for Marsden and Tromba Vector Calculus

Introduction to Finite Fields (cont.)

CODING TRUE ARITHMETIC IN THE MEDVEDEV AND MUCHNIK DEGREES

Arkansas Tech University MATH 4033: Elementary Modern Algebra Dr. Marcel B. Finan

Elements of Abstract Group Theory

Group Theory. Contents

LIMITS AND CONTINUITY

GROUPS ACTING ON A SET

Abstract Algebra Cheat Sheet

T ( a i x i ) = a i T (x i ).

1 Sets and Set Notation.

Linear Algebra I. Ronald van Luijk, 2012

System BV is NP-complete

Intuitionistic Type Theory. Per Martin-Löf

INCIDENCE-BETWEENNESS GEOMETRY

G = G 0 > G 1 > > G k = {e}

4. FIRST STEPS IN THE THEORY 4.1. A

Chapter 13: Basic ring theory

Turing Degrees and Definability of the Jump. Theodore A. Slaman. University of California, Berkeley. CJuly, 2005

Introducing Formal Methods. Software Engineering and Formal Methods

COMMUTATIVE RINGS. Definition: A domain is a commutative ring R that satisfies the cancellation law for multiplication:

Invertible elements in associates and semigroups. 1

System Description: Delphin A Functional Programming Language for Deductive Systems

Remarks on Non-Fregean Logic

Section 1.1. Introduction to R n

o-minimality and Uniformity in n 1 Graphs

PROOFS AND TYPES JEAN-YVES GIRARD PAUL TAYLOR YVES LAFONT. CAMBRIDGE UNIVERSITY PRESS Cambridge. Translated and with appendices by

So let us begin our quest to find the holy grail of real analysis.

Finite dimensional C -algebras

Computing exponents modulo a number: Repeated squaring

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

Introduction to type systems

(0, 0) : order 1; (0, 1) : order 4; (0, 2) : order 2; (0, 3) : order 4; (1, 0) : order 2; (1, 1) : order 4; (1, 2) : order 2; (1, 3) : order 4.

Foundational Proof Certificates

88 CHAPTER 2. VECTOR FUNCTIONS. . First, we need to compute T (s). a By definition, r (s) T (s) = 1 a sin s a. sin s a, cos s a

1 Symmetries of regular polyhedra

A New Generic Digital Signature Algorithm

Parametric Curves. (Com S 477/577 Notes) Yan-Bin Jia. Oct 8, 2015

The Ideal Class Group

8.1 Examples, definitions, and basic properties

On the generation of elliptic curves with 16 rational torsion points by Pythagorean triples

Transcription:

1/28 Linear Types for Continuations Alex Simpson LFCS, School of Informatics University of Edinburgh, UK Joint work with: Jeff Egger (LFCS, Edinburgh) Rasmus Møgelberg (ITU, Copenhagen)

Linear Types for Continuations 2/28 Part 1 Some CPS Translations

Linear Types for Continuations 3/28 Call-by-value CPS translation Type translation: (σ τ) Rv = σ Rv (τ Rv R) R (σ τ) Rv = σ Rv τ Rv Term translation: Γ t: τ = Γ Rv t Rv : (τ Rv R) R Faithful but not full (can also model control operators) (Kleisli category of (( ) R) R monad)

Linear Types for Continuations 4/28 Call-by-name CPS translation Type translation: (σ τ) Rn = (σ Rn R) τ Rn (σ τ) Rn = σ Rn + τ Rn Term translation: Γ t: τ = Γ Rn R t Rn : τ Rn R Faithful but not full (can also model control operators) (Opposite of Kleisli category of (( ) R) R monad)

Linear Types for Continuations 5/28 Cbv linearly-used CPS translation Type translation: (σ τ) Rv = σ Rv (τ Rv R) R (σ τ) Rv = σ Rv τ Rv Term translation: Γ t: τ = Γ Rv t Rv : (τ Rv R) R Full and faithful [Hasegawa 2002] (Kleisli category of (( ) R) R monad on intuitionistic category)

Linear Types for Continuations 6/28 Cbn linearly-used CPS translation Type translation: (σ τ) Rn =!(σ Rn R) τ Rn (σ τ) Rn = σ Rn τ Rn Term translation: Γ t: τ = Γ Rn R t Rn : τ Rn R Full and faithful [Hasegawa 2004] (Opposite of Kleisli category of (( ) R) R monad on linear category)

Linear Types for Continuations 7/28 Part 2 The Enriched Effect Calculus

Linear Types for Continuations 8/28 The Enriched Effect Calculus (EEC) [EMS 2009] A more general target language than ILL Based on distinction between values and computations. Cf. [Filinski 1996], [Levy 1999, 2004] A value is a pervasive static object, it just is. Values can be copied and discarded. There is no natural notion of linear function between general value types. A computation has a dynamic side: it can be computed/invoked/evaluated/executed. There is a natural intuition of linear functions between computation types: the argument computation is executed exactly once. Linear functions are generalised evaluation contexts/stacks.

Linear Types for Continuations 9/28 EEC type system Value types: A, B,... ::= α α 1 A B A B!A A B!A B 0 A B Computation types: A, B,... ::= α 1 A B A B!A!A B 0 A B. Typing judgements: Γ t: A Γ z : A t: B The linearly-used CPS translations land in the EEC fragment of ILL.

Linear Types for Continuations 10/28 Example rules Rules are inherited from ILL. e.g., Γ, x: A t: B Γ λx: A. t: A B Γ t: A Γ! t:! A Γ z : A t: B Γ λz : A. t: A B Γ s: A B Γ t: A Γ s(t): B Γ t:! A Γ, x: A u: B Γ let!x t in u: B Γ s: A B Γ t: A Γ s[t]: B We have the Girard isomorphism: A B =!A B

Linear Types for Continuations 11/28 Other isomorphisms of EEC (!A B) C = A (B C) = B (A C) (As value types)!a!b =!(A B)!1 A = A!(A B) C =!A!B C!A 0 = 0!A (B C) = (!A B) (!A C) (As computation types) These isomorphisms are all familiar from ILL

Linear Types for Continuations 12/28 Differences from linear logic 1. Distinction between computation types and value types. 2. A B is not assumed to be a computation type itself. Thus (A B) C value type (A B) C computation (hence value) type (A B) C not available A B C not available 3.!A B is the application of a single primitive type-constructor!( ) ( ) to A and B. (There is no symmetric.) 4. Commutativity does not hold, i.e., let!x s in let!y t in u let!y t in let!x s in u

Linear Types for Continuations 13/28 Models of EEC A model of the enriched effect calculus is given by [EMS 2009]: categories V (value types) and C (computation types) V is cartesian closed (models 1, A B, A B) C is V-enriched (models A B) C has V-powers (models A B) and V-copowers (models!a B) C has finite V-enriched products (models 1, A B) and coproducts (models 0, A B) a V-enriched adjunction F U : C V (models!a) We write the entire model as F U : C V. (All structure other than the adjunction is determined by universal properties.)

Linear Types for Continuations 14/28 Models of ILL are models of EEC A linear/nonlinear model [Benton 1995] is given by symmetric monoidal closed category C (the linear category), a cartesian closed category V (the intuitionistic category) and a monoidal adjunction F U : C V. If C also has finite products and coproducts then the model is said to have additives Proposition [EMS 2009] If F U : C V is a linear/nonlinear model with additives then it is a model of the enriched effect calculus. N.B. The linear-logic syntax of EEC agrees with the interpretation of ILL in a linear/nonlinear model. EEC is a fragment of ILL interpretable in a wider class of models.

Linear Types for Continuations 15/28 Models of computational effects expand to models of EEC Call-by-push-value (CBPV) [Levy 1999,2004] is a type theory for computational effects extending Moggi s computational metalanguage [Moggi 1991] to include call-by-name. Adjunction models [Levy 2005] are the natural models of call-by-push-value (CBPV), generalising Moggi s strong monads. Every model of EEC is an adjunction model of CBPV Theorem [EMS 2009] Every adjunction model of CBPV fully embeds in a model of the enriched effect calculus. EEC is a conservative extension of CBPV (hence of Moggi s computational metalanguage) with a gain in expressivity and (essentially) no loss in range of applicability

Linear Types for Continuations 16/28 EEC as a metalanguage for effects Understand!A as Moggi s type T A of computations (with effects) that produce results of type A The call-by-value (cbv) translation [Moggi] translates a simple type σ to a value type σ v. The call-by-name (cbn) translation (cf. [Filinski, Levy]) translates σ to a computation type σ n. (σ τ) v = σ v τ v (σ τ) n = σ n τ n (σ τ) v = σ v!τ v (σ τ) n = σ n τ n. Typing judgements Γ t: σ get translated to: Γ v t v :!σ v The new linear connectives are not used! Γ n t n : σ n

Linear Types for Continuations 17/28 Part 3 Linearly-used CPS in EEC

Linear Types for Continuations 18/28 Linearly-used CPS translation of EEC to itself [EMS 2010] Let R be a chosen computation type. A value type A translates to a value type A VR. A computation type A translates to a computation type A CR. These translations satisfy A VR = A CR R. A typing judgement Γ t: A translates to Γ VR t VR : A VR A typing judgement Γ z : A u: B translates to Γ VR z : B CR u CR : A CR

Linear Types for Continuations 19/28 α VR = α α VR = α CR R α CR = α 1 VR = 1 1 CR = 0 (A B) VR = A VR B VR (A B) CR = A CR B CR (A B) VR = A VR B VR (A B) CR =! A VR B CR (!A) VR = (!A) CR R (!A) CR = A VR R (A B) VR = B CR A CR (!A B) VR = (!A B) CR R (!A B) CR = A VR B CR (0) VR = (0) CR R (0) CR = 1 (A B) VR = (A B) CR R (A B) CR = A CR B CR R VR = R R CR =! 1

Linear Types for Continuations 20/28 Recovering cbv linearly-used CPS translation (σ τ) Rv = σ Rv (τ Rv R) R (σ τ) Rv = σ Rv τ Rv Γ t: τ = Γ Rv t Rv : (τ Rv R) R Recovered as: σ Rv t Rv = (σ v ) VR = (t v ) VR

Linear Types for Continuations 21/28 Recovering cbn linearly-used CPS translation (σ τ) Rn =!(σ Rn R) τ Rn (σ τ) Rn = σ Rn τ Rn Γ t: τ = Γ Rn R t Rn : τ Rn R Recovered as: σ Rn = (σ n ) CR t Rn = (t n ) VR

Linear Types for Continuations 22/28 Fundamental theorem of EEC translation Theorem (Involution property [EMS 2010]) We have isomorphisms A = A VR VR A = CR CR A modulo which t = t VR VR and u = u CR CR. Our proof of this is semantic. The translation arises as a self-duality of the initial (syntactic) model of EEC. (Obtaining a syntactic proof looks like a formidable exercise.) Corollary The translations ( ) VR and ( ) CR are full and faithful. Corollary The translations ( ) Rv and ( ) Rn are full and faithful. [Hasegawa 2002, 2004] has analogous results for the ( ) Rv and ( ) Rn translations into ILL rather than EEC

Linear Types for Continuations 23/28 Part 4 Adding Control to EEC

Linear Types for Continuations 24/28 EEC + Control New value type: stk A. New typing rules: Γ, x: stk A t: A Γ letstk x. t: A Γ t: stk A Γ u: A Γ chngstk t. u: B Γ t: stk B Γ z : A u: B Γ t [z]u: stk A Γ ignored: stk 0 Plus suitable equations. Modelled on CBPV + Control [Levy 2004]

Linear Types for Continuations 25/28 A reformulation of EEC + Control Interpret stk A as A 0 and add canonical isomorphisms A = (A 0) 0 I.e., add constants: r A : ((A 0) 0) A and equations making them inverse to the canonical λz : A. λy : A 0. y[z] : A (A 0) 0 This appears in [MS 2007] in the context of a polymorphic language. (N.B. Canonical A = (A 0) 0 is incompatible with ILL)

Linear Types for Continuations 26/28 Jump With Argument (JWA) If we add canonical isomorphisms for computation and value types we obtain Jump With Argument [Levy 2004]. A = (A 0) 0 (1) A = (A 0) 0 (2) Principle (2) is harmless in the sense that EEC + (1) + (2) can be interpreted in EEC + (1) without changing the computation types. This is a reformulation of the equivalence between CBPV + Control and JWA in [Levy 2004]

Linear Types for Continuations 27/28 Summary The enriched effect calculus conservatively extends effect calculi (Moggi s computational metalanguage, CBPV) with much of the expressivity of intuitionistic linear logic. Models of EEC strictly generalises models of ILL. The cbv and cbn liinearly-used CPS translations extend to a translation of EEC into itself. (Such a self translation is not available for for ILL or CBPV.) Control can be added to EEC by simple axioms involving. (Such axioms do not make sense in ILL.) In general EEC is a promising language for representing linear usage of effects. E.g., linear-usage of (local) state [Møgelberg & Staton].

Linear Types for Continuations 28/28 EMS literature references [MS 2007] Relational parametricity for control considered as a computational effect. MFPS 2007. [EMS 2009] Enriching an effect calculus with linear types. CSL 2009. [EMS 2010] Linearly-used Continuations in the Enriched Effect Calculus. FoSSaCS 2010.