Positively Dependent Types Dan Licata and Robert Harper Carnegie Mellon University 1
Dan’s thesis New dependently typed programming language for programming with binding and scope Applications: Domain-specific logics for reasoning about code Mechanized metatheory 2
Dan’s thesis New dependently typed programming language for programming with binding and scope Applications: Domain-specific logics for reasoning about code Mechanized metatheory Based on polarized type theory 2
Polarity [Girard ’93] Sums A + B are positive data: Introduced by choosing inl or inr Eliminated by pattern-matching ML functions A → B are negative computation: Introduced by pattern-matching on A Eliminated by choosing an A to apply to 3
Focusing [Andreoli ’92] Sums A + B are positive data: Introduced by choosing inl or inr Eliminated by pattern-matching ML functions A → B are negative computation: Introduced by pattern-matching on A Eliminated by choosing an A to apply to 4
Focusing [Andreoli ’92] Sums A + B are positive data: Focus = make choices Introduced by choosing inl or inr Eliminated by pattern-matching ML functions A → B are negative computation: Introduced by pattern-matching on A Eliminated by choosing an A to apply to 4
Focusing [Andreoli ’92] Sums A + B are positive data: Introduced by choosing inl or inr Eliminated by pattern-matching ML functions A → B are negative computation: Introduced by pattern-matching on A Eliminated by choosing an A to apply to 5
Focusing [Andreoli ’92] Sums A + B are positive data: Inversion = respond to all Introduced by choosing inl or inr possible choices Eliminated by pattern-matching ML functions A → B are negative computation: Introduced by pattern-matching on A Eliminated by choosing an A to apply to 5
Higher-order focusing Zeilberger’s higher-order formalism: Type theory organized around distinction between positive data and negative computation Positive Data Negative Computation products (eager) products (lazy) sums functions natural numbers streams inductive types coinductive types 6
Higher-order focusing Zeilberger’s higher-order formalism: Type theory organized around distinction between positive data and negative computation Pattern matching represented abstractly by meta-level functions from patterns to expressions, using an iterated inductive definition 7
Higher-order focusing Applications so far: 8
Higher-order focusing Applications so far: Curry-Howard for pattern matching [Zeilberger POPL’08; cf. Krishnaswami POPL’09] 8
Higher-order focusing Applications so far: Curry-Howard for pattern matching [Zeilberger POPL’08; cf. Krishnaswami POPL’09] Logical account of evaluation order [Zeilberger APAL] 8
Higher-order focusing Applications so far: Curry-Howard for pattern matching [Zeilberger POPL’08; cf. Krishnaswami POPL’09] Logical account of evaluation order [Zeilberger APAL] Analysis of operationally sensitive typing phenomena [Zeilberger PLPV’09] 8
Higher-order focusing Applications so far: Curry-Howard for pattern matching [Zeilberger POPL’08; cf. Krishnaswami POPL’09] Logical account of evaluation order [Zeilberger APAL] Analysis of operationally sensitive typing phenomena [Zeilberger PLPV’09] Positive function space for representing variable binding [LZH LICS’08] 8
Positive function space Permits LF-style representation of binding: framework provides α -equivalence, substitution Eliminated by pattern matching = structural induction modulo α 9
Positive function space Permits LF-style representation of binding: framework provides α -equivalence, substitution Eliminated by pattern matching = structural induction modulo α But no dependent types... 9
Positively dependent types Contributions: 1. Extend higher-order focusing with a simple form of dependency 2. Formalize the language in Agda 10
Positively dependent types Key idea: Allow dependency on positive data, but not negative computation 11
Positively dependent types Key idea: Allow dependency on positive data, but not negative computation Enough for simple applications: Lists indexed by their lengths ( Vec[n:nat] ) Judgements on higher-order abstract syntax represented with positive functions 11
Positively dependent types Key idea: Allow dependency on positive data, but not negative computation Avoids complications of negative dependency: Equality is easy for data, hard for computation Computations are free to be effectful 12
Positively dependent types 1. Type and term levels share the same data (like Agda, Epigram, Cayenne, NuPRL, …) 2. But have different notions of computation (like DML, Omega, ATS, …) 13
Polarized type theory Intuitionistic logic: A + ::= nat | A + ⊗ B + | 1 | A + ⊕ B + | 0 | ↓ A - A - ::= A + → B - | A - & B - | ⊤ | ↑ A + 14
Polarized type theory Intuitionistic logic: A + ::= nat | A + ⊗ B + | 1 | A + ⊕ B + | 0 | ↓ A - A - ::= A + → B - | A - & B - | ⊤ | ↑ A + Allow dependency on values of purely positive types (no ↓ A - ) 14
Polarized type theory Intuitionistic logic (see paper): A + ::= nat | A + ⊗ B + | 1 | A + ⊕ B + | 0 | ↓ A - A - ::= A + → B - | A - & B - | ⊤ | ↑ A + Minimal logic (this talk): A + ::= nat | A + ⊗ B + | 1 | A + ⊕ B + | 0 | ¬ A + Purely positive types: no ¬A + ( = ↓ (A + → #) ) 15
Outline 1. Simply typed higher-order focusing 2. Positively dependent types 16
Outline 1. Simply typed higher-order focusing 2. Positively dependent types 17
Higher-order focusing Specify types by their patterns Type-independent focusing framework Focus phase = choose a pattern Inversion phase = pattern-matching 18
Higher-order focusing Specify types by their patterns Type-independent focusing framework Focus phase = choose a pattern Inversion phase = pattern-matching 19
Patterns Proof pattern gives us the outline of a proof, but leaves holes for refutations B false A false ¬B true ¬A true ¬B ⊕ ¬C true ¬A ⊗ (¬B ⊕ ¬C) true 20
Patterns A 1 false, ..., A n false ⊩ A true 21
Patterns A 1 false, ..., A n false ⊩ A true Δ Δ ⊩ A true : there is a proof pattern for A, leaving holes for refutations of A 1 ... A n 21
Pattern rules A false ⊩ ¬A true Δ ₁ ⊩ A true Δ ₂ ⊩ B true ∙ ⊩ 1 true Δ ₁ Δ ₂ ⊩ A ⊗ B true Δ ⊩ A true Δ ⊩ B true (no rule for 0) Δ ⊩ A ⊕ B true Δ ⊩ A ⊕ B true 22
Proof terms B false ⊩ ¬B true B false ⊩ ¬B ⊕ ¬C true A false ⊩ ¬A true A false, B false ⊩ ¬A ⊗ (¬B ⊕ ¬C) true ≈ ( κ ₁ , inl κ ₂ ) continuation variables
Proof terms κ 2 B false ⊩ ¬B true inl κ ₁ B false ⊩ ¬B ⊕ ¬C true A false ⊩ ¬A true (_,_) A false, B false ⊩ ¬A ⊗ (¬B ⊕ ¬C) true ≈ ( κ ₁ , inl κ ₂ ) continuation variables
Higher-order focusing Specify types by their patterns Type-independent focusing framework Focus phase = choose a pattern Inversion phase = pattern-matching 24
Focused proofs iterated inductive definition Δ ⊩ A true Γ ⊢ Δ Δ ⊩ A true Γ , Δ ⊢ # Γ ⊢ A true Γ ⊢ A false A false ∊ Δ Γ ⊢ A false A false ∊ Δ Γ ⊢ A true Γ ⊢ Δ Γ ⊢ #
Focused proofs iterated inductive definition Δ ⊩ A true Γ ⊢ Δ Δ ⊩ A true Γ , Δ ⊢ # Γ ⊢ A true Γ ⊢ A false focus inversion A false ∊ Δ Γ ⊢ A false A false ∊ Δ Γ ⊢ A true Γ ⊢ Δ Γ ⊢ #
K :: Γ K :: Γ A false A false Example continuation p E Δ ⊩ ¬A ⊗ (¬B ⊕ ¬C) true Γ , Δ ⊢ # K deriv. of Γ ⊢ ¬A ⊗ (¬B ⊕ ¬C) false 26
K :: Γ K :: Γ A false A false Example continuation p E Δ ⊩ ¬A ⊗ (¬B ⊕ ¬C) true Γ , Δ ⊢ # K deriv. of Γ ⊢ ¬A ⊗ (¬B ⊕ ¬C) false { E 1 ( κ ₁ , inl κ ₂ ) ↦ Γ , κ ₁ : A false, κ 2 : B false, ⊢ # K E 2 ( κ ₁ , inr κ 3 ) ↦ Γ , κ ₁ : A false, κ 3 : C false, ⊢ # 26
Outline 1. Simply typed higher-order focusing 2. Positively dependent types 27
Higher-order focusing all the changes are here Specify types by their patterns Type-independent focusing framework Focus phase = choose a pattern Inversion phase = pattern-matching 28
Positively dependent types 1. Allow indexing by closed patterns = values of purely positive types 29
Patterns Δ ⊩ nat true nat : z s ∙ ⊩ nat true Δ ⊩ nat true 30
Patterns Δ ⊩ nat true nat : z s ∙ ⊩ nat true Δ ⊩ nat true vec[ p :: ∙ ⊩ nat true ]: nil ∙ ⊩ vec[z] true Δ 1 ⊩ bool true Δ 2 ⊩ vec[ p ] true cons Δ 1 Δ 2 ⊩ vec[s p ] true 30
Positively dependent types 1. Allow indexing by closed patterns = values of purely positive types 2. Syntax of ( Σ x:A.B) specified by pattern-matching: gives type-level computation (large eliminations) 31
Dependent pairs p A type [] ⊩ A true τ (p) type Σ A τ type 32
Dependent pairs p A type [] ⊩ A true τ (p) type Σ A τ type p ∙ ⊩ A true Δ ⊩ τ (p) true pair Δ ⊩ Σ A τ true 32
Recommend
More recommend