The Next 700 Modal Type Assignment Systems Andreas Abel Talk - - PowerPoint PPT Presentation

the next 700 modal type assignment systems
SMART_READER_LITE
LIVE PREVIEW

The Next 700 Modal Type Assignment Systems Andreas Abel Talk - - PowerPoint PPT Presentation

The Next 700 Modal Type Assignment Systems Andreas Abel Talk presented by Andrea Vezzosi Department of Computer Science and Engineering Chalmers and Gothenburg University, Sweden Types for Proofs and Programs Annual Meeting 2015 Tallinn,


slide-1
SLIDE 1

The Next 700 Modal Type Assignment Systems

Andreas Abel Talk presented by Andrea Vezzosi

Department of Computer Science and Engineering Chalmers and Gothenburg University, Sweden

Types for Proofs and Programs Annual Meeting 2015 Tallinn, Estonia 18 May 2015

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 1 / 19

slide-2
SLIDE 2

Introduction

Motivation

Grand goal: integrate analyses (positivity, termination, strictness) into dependent type theory. Reason: with meta variables, type checking not cleanly separable from

  • ther analyses.

A lot of type-based analyses out there:

Strictness. Relevance. Linearity. Positivity.

Can be formulated as non-standard type systems. Sometimes a bit ad-hoc. Can we systematize them?

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 2 / 19

slide-3
SLIDE 3

Introduction

Simply Typed Lambda-Calculus With Largest Type

Terms t, u ::= x | λxt | t u (untyped). Type assignment Γ ⊢ t : A. Types A, B ::= ⊤ | A → B. Contexts Γ are total functions from term variables to types.

Empty context ε is constant function ε(x) = ⊤. Domain dom(Γ) = {x | Γ(x) = ⊤}. Update/extension Γ′ = (Γ, x :A) is Γ′(y) = U if y = x Γ(y)

  • therwise

Singleton context x :A is (ε, x :A).

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 3 / 19

slide-4
SLIDE 4

Introduction

Trivial subtyping

Subtyping A ≤ B iff A = B or B = ⊤. ⊤ A B · · · Greatest lower bound A ∧ B is undefined except that A ∧ ⊤ = ⊤ ∧ A = A ∧ A = A.

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 4 / 19

slide-5
SLIDE 5

Introduction

Context subsumption = Weakening

Subsumption Γ ≤ ∆ is pointwise: ∀x. Γ(x) ≤ ∆(x). ε x :B x :A y :B x :B, z :C

  • x :A, y :B

y :B, z :C x :A, y :B, z :C Joining contexts Γ ∧ ∆ is pointwise (undef. if undef. at some x): (Γ ∧ ∆)(x) = Γ(x) ∧ ∆(x) Note: ε ∧ Γ = Γ ∧ ε = Γ ∧ Γ = Γ.

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 5 / 19

slide-6
SLIDE 6

Introduction

Simple Type Assignment

x : A ⊢ x : A hyp Γ, x : A ⊢ t : B Γ ⊢ λxt : A → B abs Γ ⊢ t : A → B ∆ ⊢ u : A Γ ∧ ∆ ⊢ t u : B app Γ ≤ ∆ ∆ ⊢ t : A A ≤ B Γ ⊢ t : B sub Looks linear. But app allows contraction. And sub allows weakening.

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 6 / 19

slide-7
SLIDE 7

Introduction

Exact Quantitative Typing

Quantifies resource use exactly. Quantified type Q ::= qA, quantity p, q ∈ N. Types A, B ::= ⊤ | Q → B. E.g. 5A → B: to produce one B, we need exactly 5 A. Context Γ maps variables x to quantified types Q. Scaling p(qA) = (pq)A and (pΓ)(x) = p(Γ(x)). Partial sum pA + qB = (p + q)(A ∧ B). Pointwise context sum (Γ + ∆)(x) = Γ(x) + ∆(x).

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 7 / 19

slide-8
SLIDE 8

Introduction

Exact Quantitative Type Assignment

x : 1A ⊢ x : A hyp Γ, x : qA ⊢ t : B Γ ⊢ λxt : qA → B abs Γ ⊢ t : qA → B ∆ ⊢ u : qA Γ + ∆ ⊢ t u : B app Γ ⊢ t : A qΓ ⊢ t : qA mod mod introduces quantified types. app splits resources between function and argument.

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 8 / 19

slide-9
SLIDE 9

Introduction

Wasting (Weakening)

Subtyping quantified types. q ≥ q′ A ≤ A′ qA ≤ q′A′ Weakening. Γ ≤ ∆ ∆ ⊢ t : A A ≤ B Γ ⊢ t : B sub

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 9 / 19

slide-10
SLIDE 10

Introduction

Typical Quantitative Type Systems

Strictness: Is a variable used at least once? Quantities: 0.. and 1.. Relevance: Is a variable used never? Quantities: 0 and 1.. Linear typing: Is a variable used exactly once or unrestrictedly? Quantities: 1 and 0..

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 10 / 19

slide-11
SLIDE 11

Introduction

Quantitative Typing, Revisited

Quantities q ∈ P are sets of natural numbers. P ⊆ P(N) is partially ordered by p ≤ q ⇐ ⇒ p ⊇ q P should form a monoid with composition pq = {mn | m ∈ p and n ∈ q} and a suitable unit 1. x : 1A ⊢ x : A hyp Sum p + q is smallest set r ∈ P such that m + n ∈ r for all m ∈ p and n ∈ q (might not exists). Default element p0 for empty context ε(x) = p0⊤ (controls weakening).

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 11 / 19

slide-12
SLIDE 12

Introduction

Example 1: Linear typing

P = {1, !} with 1 = {1} (linear) and ! = N (unrestricted). pq 1 N 1 1 N N N N p + q 1 N 1 / N N N N 1 + 1 undefined: no contraction for linear hypotheses! p0 = ! ≤ 1: weakening only with unrestricted hypotheses. (x : !A) ≤ (x : !⊤) = ε Hypothesis rule usable for ! via sub: (x :!A) ≤ (x :1A) x :1A ⊢ x : A x :!A ⊢ x : A

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 12 / 19

slide-13
SLIDE 13

Introduction

Example 2: Strictness typing

P = {L, S} with L = N (lazy) and S = N \ {0} = 1 (strict). pq L S L L L S L S p + q L S L L S S S S p0 = L ≤ S: weakening only with lazy hypotheses! (x : LA) ≤ (x : S⊤) = ε Hypothesis rule usable for L via sub: (x :LA) ≤ (x :SA) x :SA ⊢ x : A x :LA ⊢ x : A

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 13 / 19

slide-14
SLIDE 14

Introduction

Example 3: Relevance typing

P = {0, 1} with 0 = {0} (unused) and 1 = N \ {0} = 1 (used). P is discrete: 0 ≤ 1 ≤ 0. pq 1 1 1 p + q 1 1 1 1 1 p0 = 0: weakening only with unused hypotheses! (x : 0A) ≤ (x : 1⊤) = ε Irrelevant hypotheses are unusable x :0A ⊢ x : A

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 14 / 19

slide-15
SLIDE 15

Introduction

Variance / Monotonicity / Polarity / Positivity

Scala: type operator variance for subtyping. Coq/Agda: positivity checking for inductive/coinductive types. 4-point lattice: p variance monotonicity

  • ccurrence

∅ invariant constant none + covariant monotone positive − contravariant antitone negative ± mixed-variant any function both / don’t know Function composition is pq. Combine variable occurrences in subterms with p + q.

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 15 / 19

slide-16
SLIDE 16

Introduction

Positivity Typing

Partially ordered monoid P = {∅, +, −, ±}. ∅ + − ± pq ± + − ∅ ± ± ± ± ∅ + ± + − ∅ − ± − + ∅ ∅ ∅ ∅ ∅ ∅ p + q ± + − ∅ ± ± ± ± ± + ± + ± + − ± ± − − ∅ ± + − ∅ Encoding: p ≤ q = p ⊇ q and p + q = p ∪ q where ∅ + − ± {} {+1} {−1} {+1, −1} Default polarity p0 = ∅: weaken with anything.

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 16 / 19

slide-17
SLIDE 17

Introduction

Modal types

Make qA first class: A, B ::= ⊤ | qA | A → B. Back to lambda-calculus rules plus mod. x : A ⊢ x : A hyp Γ, x : A ⊢ t : B Γ ⊢ λxt : A → B abs Γ ⊢ t : A → B ∆ ⊢ u : A Γ + ∆ ⊢ t u : B app Γ ≤ ∆ ∆ ⊢ t : A A ≤ B Γ ⊢ t : B sub Γ ⊢ t : A qΓ ⊢ t : qA mod

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 17 / 19

slide-18
SLIDE 18

Introduction

Linear Types, Revisited

P = {1, !}, let 1A = A. Observe !!A = !A. Promotion is an instance of mod. !Γ ⊢ t : A !Γ ⊢ t : !A mod

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 18 / 19

slide-19
SLIDE 19

Introduction

Conclusions & Further work

A fairly generic simple/modal type system parametrized over a partially ordered monoid P with sum and default element p0. Captures several well-known non-standard type system. Further work:

Nakano’s modality for recursion. Semantics? Connected to Kripke models?

Recent related work: Conor McBride uses worlds to integrate linear and dependent types.

Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 19 / 19