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
Introduction Motivation Grand goal: integrate analyses (positivity, termination, strictness) into dependent type theory. Reason: with meta variables, type checking not cleanly separable from other 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
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 ) � = ⊤} . � U if y = x Update/extension Γ ′ = (Γ , x : A ) is Γ ′ ( y ) = Γ( y ) otherwise Singleton context x : A is ( ε, x : A ). Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 3 / 19
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
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
Introduction Simple Type Assignment Γ , x : A ⊢ t : B x : A ⊢ x : A hyp Γ ⊢ λ xt : A → B abs Γ ⊢ t : A → B ∆ ⊢ u : A app Γ ∧ ∆ ⊢ t u : B Γ ≤ ∆ ∆ ⊢ t : A A ≤ B sub Γ ⊢ t : B Looks linear . But app allows contraction. And sub allows weakening. Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 6 / 19
Introduction Exact Quantitative Typing Quantifies resource use exactly. Quantified type Q ::= qA , quantity p , q ∈ N . Types A , B ::= ⊤ | Q → B . E.g. 5 A → 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
Introduction Exact Quantitative Type Assignment Γ , x : qA ⊢ t : B x : 1 A ⊢ x : A hyp Γ ⊢ λ xt : qA → B abs Γ ⊢ t : qA → B ∆ ⊢ u : qA app Γ + ∆ ⊢ t u : B Γ ⊢ 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
Introduction Wasting (Weakening) Subtyping quantified types. q ≥ q ′ A ≤ A ′ qA ≤ q ′ A ′ Weakening. Γ ≤ ∆ ∆ ⊢ t : A A ≤ B sub Γ ⊢ t : B Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 9 / 19
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
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 : 1 A ⊢ 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 p 0 for empty context ε ( x ) = p 0 ⊤ (controls weakening). Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 11 / 19
Introduction Example 1: Linear typing P = { 1 , ! } with 1 = { 1 } (linear) and ! = N (unrestricted). pq 1 N p + q 1 N 1 1 N 1 / N N N N N N N 1 + 1 undefined: no contraction for linear hypotheses! p 0 = ! ≤ 1 : weakening only with unrestricted hypotheses. ( x : ! A ) ≤ ( x : ! ⊤ ) = ε Hypothesis rule usable for ! via sub : ( x :! A ) ≤ ( x : 1 A ) x : 1 A ⊢ x : A x :! A ⊢ x : A Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 12 / 19
Introduction Example 2: Strictness typing P = { L , S } with L = N (lazy) and S = N \ { 0 } = 1 (strict). p + q pq L S L S L L L L L S S L S S S S p 0 = L ≤ S : weakening only with lazy hypotheses! ( x : L A ) ≤ ( x : S ⊤ ) = ε Hypothesis rule usable for L via sub : ( x : L A ) ≤ ( x : S A ) x : S A ⊢ x : A x : L A ⊢ x : A Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 13 / 19
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 0 1 p + q 0 1 0 0 0 0 0 1 1 0 1 1 1 1 p 0 = 0 : weakening only with unused hypotheses! ( x : 0 A ) ≤ ( x : 1 ⊤ ) = ε Irrelevant hypotheses are unusable x : 0 A � ⊢ x : A Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 14 / 19
Introduction Variance / Monotonicity / Polarity / Positivity Scala: type operator variance for subtyping. Coq/Agda: positivity checking for inductive/coinductive types. 4-point lattice: variance monotonicity occurrence p ∅ 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
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 p 0 = ∅ : weaken with anything. Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 16 / 19
Introduction Modal types Make qA first class: A , B ::= ⊤ | qA | A → B . Back to lambda-calculus rules plus mod . Γ , x : A ⊢ t : B x : A ⊢ x : A hyp Γ ⊢ λ xt : A → B abs Γ ⊢ t : A → B ∆ ⊢ u : A app Γ + ∆ ⊢ t u : B Γ ≤ ∆ ∆ ⊢ t : A A ≤ B Γ ⊢ t : A sub q Γ ⊢ t : qA mod Γ ⊢ t : B Abel (Chalmers/GU) Next 700 Modal TAS TYPES 2015 17 / 19
Introduction Linear Types, Revisited P = { 1 , ! } , let 1 A = 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
Introduction Conclusions & Further work A fairly generic simple/modal type system parametrized over a partially ordered monoid P with sum and default element p 0 . 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
Recommend
More recommend