Positively Dependent Types Dan Licata and Robert Harper Carnegie - - PowerPoint PPT Presentation

positively dependent types
SMART_READER_LITE
LIVE PREVIEW

Positively Dependent Types Dan Licata and Robert Harper Carnegie - - PowerPoint PPT Presentation

Positively Dependent Types Dan Licata and Robert Harper Carnegie Mellon University 1 Dans thesis New dependently typed programming language for programming with binding and scope Applications: Domain-specific logics for reasoning about


slide-1
SLIDE 1

Positively Dependent Types

1

Dan Licata and Robert Harper

Carnegie Mellon University

slide-2
SLIDE 2

2

Dan’s thesis

New dependently typed programming language for programming with binding and scope Domain-specific logics for reasoning about code Mechanized metatheory Applications:

slide-3
SLIDE 3

2

Dan’s thesis

New dependently typed programming language for programming with binding and scope Domain-specific logics for reasoning about code Mechanized metatheory Applications: Based on polarized type theory

slide-4
SLIDE 4

3

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

slide-5
SLIDE 5

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

slide-6
SLIDE 6

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

Focus = make choices

slide-7
SLIDE 7

5

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

slide-8
SLIDE 8

5

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

Inversion = respond to all possible choices

slide-9
SLIDE 9

6

Higher-order focusing

Zeilberger’s higher-order formalism: Type theory organized around distinction between positive data and negative computation Positive Data products (eager) sums natural numbers inductive types Negative Computation products (lazy) functions streams coinductive types

slide-10
SLIDE 10

7

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

slide-11
SLIDE 11

8

Higher-order focusing

Applications so far:

slide-12
SLIDE 12

8

Higher-order focusing

Applications so far: Curry-Howard for pattern matching [Zeilberger POPL’08; cf. Krishnaswami POPL’09]

slide-13
SLIDE 13

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]

slide-14
SLIDE 14

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]

slide-15
SLIDE 15

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]

slide-16
SLIDE 16

9

Positive function space

Permits LF-style representation of binding: framework provides α-equivalence, substitution Eliminated by pattern matching = structural induction modulo α

slide-17
SLIDE 17

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...

slide-18
SLIDE 18

10

Positively dependent types

  • 1. Extend higher-order focusing with

a simple form of dependency

  • 2. Formalize the language in Agda

Contributions:

slide-19
SLIDE 19

11

Positively dependent types

Key idea: Allow dependency on positive data, but not negative computation

slide-20
SLIDE 20

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

slide-21
SLIDE 21

12

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

slide-22
SLIDE 22

13

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, …)

slide-23
SLIDE 23

14

Polarized type theory

Intuitionistic logic: A+ ::= nat | A+ ⊗ B+ | 1 | A+ ⊕ B+ | 0 | ↓ A- A- ::= A+ → B- | A- & B- | ⊤ | ↑ A+

slide-24
SLIDE 24

14

Polarized type theory

Allow dependency on values of purely positive types (no ↓A-) Intuitionistic logic: A+ ::= nat | A+ ⊗ B+ | 1 | A+ ⊕ B+ | 0 | ↓ A- A- ::= A+ → B- | A- & B- | ⊤ | ↑ A+

slide-25
SLIDE 25

15

Polarized type theory

A+ ::= nat | A+ ⊗ B+ | 1 | A+ ⊕ B+ | 0 | ↓ A- A- ::= A+ → B- | A- & B- | ⊤ | ↑ A+ Intuitionistic logic (see paper): A+ ::= nat | A+ ⊗ B+ | 1 | A+ ⊕ B+ | 0 | ¬ A+ Minimal logic (this talk): Purely positive types: no ¬A+ ( = ↓(A+ → #) )

slide-26
SLIDE 26

16

Outline

  • 1. Simply typed higher-order focusing
  • 2. Positively dependent types
slide-27
SLIDE 27

17

Outline

  • 1. Simply typed higher-order focusing
  • 2. Positively dependent types
slide-28
SLIDE 28

18

Higher-order focusing

Specify types by their patterns Type-independent focusing framework Focus phase = choose a pattern Inversion phase = pattern-matching

slide-29
SLIDE 29

19

Higher-order focusing

Specify types by their patterns Type-independent focusing framework Focus phase = choose a pattern Inversion phase = pattern-matching

slide-30
SLIDE 30

Patterns

Proof pattern gives us the outline of a proof, but leaves holes for refutations

20

¬A⊗(¬B⊕¬C) true ¬A true ¬B⊕¬C true A false ¬B true B false

slide-31
SLIDE 31

Patterns

21

A1 false, ..., An false ⊩ A true

slide-32
SLIDE 32

Patterns

21

Δ ⊩ A true : there is a proof pattern for A,

leaving holes for refutations of A1 ... An

A1 false, ..., An false ⊩ A true Δ

slide-33
SLIDE 33

Pattern rules

22

Δ₁ ⊩ A true Δ₂ ⊩ B true Δ₁Δ₂ ⊩ A⊗B true

∙ ⊩ 1 true

Δ ⊩ A true Δ ⊩ A⊕B true Δ ⊩ B true Δ ⊩ A⊕B true (no rule for 0)

A false ⊩ ¬A true

slide-34
SLIDE 34

Proof terms

B false ⊩ ¬B true B false ⊩ ¬B⊕¬C true A false ⊩ ¬A true A false, B false ⊩ ¬A⊗(¬B⊕¬C) true

continuation variables

(κ₁, inl κ₂)

slide-35
SLIDE 35

Proof terms

B false ⊩ ¬B true B false ⊩ ¬B⊕¬C true A false ⊩ ¬A true A false, B false ⊩ ¬A⊗(¬B⊕¬C) true

continuation variables

(κ₁, inl κ₂) κ₁ κ2 inl (_,_)

slide-36
SLIDE 36

24

Higher-order focusing

Specify types by their patterns Type-independent focusing framework Focus phase = choose a pattern Inversion phase = pattern-matching

slide-37
SLIDE 37

Focused proofs

Δ ⊩ A true Γ ⊢ Δ Γ ⊢ A true A false ∊ Δ Γ ⊢ A false Γ ⊢ Δ A false ∊ Δ Γ ⊢ A true Γ ⊢ # Δ ⊩ A true Γ, Δ ⊢ # Γ ⊢ A false

iterated inductive definition

slide-38
SLIDE 38

Focused proofs

Δ ⊩ A true Γ ⊢ Δ Γ ⊢ A true A false ∊ Δ Γ ⊢ A false Γ ⊢ Δ A false ∊ Δ Γ ⊢ A true Γ ⊢ # Δ ⊩ A true Γ, Δ ⊢ # Γ ⊢ A false

focus inversion iterated inductive definition

slide-39
SLIDE 39

Example continuation

26

p E Δ ⊩ ¬A⊗(¬B⊕¬C) true Γ, Δ ⊢ # Γ ⊢ ¬A⊗(¬B⊕¬C) false K deriv. of K :: Γ A false K :: Γ A false

slide-40
SLIDE 40

Example continuation

26

p E Δ ⊩ ¬A⊗(¬B⊕¬C) true Γ, Δ ⊢ # Γ ⊢ ¬A⊗(¬B⊕¬C) false (κ₁, inl κ₂) ↦ E1 Γ, κ₁: A false, κ2: B false, ⊢ # (κ₁, inr κ3) ↦ E2 Γ, κ₁: A false, κ3: C false, ⊢ #

{

K K deriv. of K :: Γ A false K :: Γ A false

slide-41
SLIDE 41

27

Outline

  • 1. Simply typed higher-order focusing
  • 2. Positively dependent types
slide-42
SLIDE 42

28

Higher-order focusing

Specify types by their patterns Type-independent focusing framework Focus phase = choose a pattern Inversion phase = pattern-matching

all the changes are here

slide-43
SLIDE 43

29

  • 1. Allow indexing by closed patterns

= values of purely positive types

Positively dependent types

slide-44
SLIDE 44

30

Patterns

∙ ⊩ nat true

Δ ⊩ nat true Δ ⊩ nat true nat: z s

slide-45
SLIDE 45

30

Patterns

∙ ⊩ nat true

Δ ⊩ nat true Δ ⊩ nat true nat: z s Δ1 ⊩ bool true Δ2 ⊩ vec[p] true Δ1Δ2 ⊩ vec[s p] true cons ∙ ⊩ vec[z] true vec[p :: ∙ ⊩ nat true]: nil

slide-46
SLIDE 46

31

  • 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)

Positively dependent types

slide-47
SLIDE 47

32

Dependent pairs

A type [] ⊩ A true τ(p) type Σ A τ type p

slide-48
SLIDE 48

32

Dependent pairs

∙ ⊩ A true Δ ⊩ τ(p) true Δ ⊩ Σ A τ true pair A type [] ⊩ A true τ(p) type Σ A τ type p p

slide-49
SLIDE 49

33

Dependent pairs

A type [] ⊩ A true τ(p) type Σ A τ type p

List: Σ nat (p ↦ vec[p]) Pattern: (pair 2 (cons true (cons false nil)))

∙ ⊩ A true Δ ⊩ τ(p) true Δ ⊩ Σ A τ true pair p

slide-50
SLIDE 50

34

Dependent pairs

A type [] ⊩ A true τ(p) type Σ A τ type p

Check: Σ bool (true ↦ 1; false ↦ 0) Only pattern: pair true <>

∙ ⊩ A true Δ ⊩ τ(p) true Δ ⊩ Σ A τ true pair p

slide-51
SLIDE 51

35

Dependent pairs

A type [] ⊩ A true τ(p) type Σ A τ type p

Recursive Vec: Σ nat (z ↦ 1; s(z) ↦ bool; s(s(z)) ↦ bool ⊗ bool; ...)

∙ ⊩ A true Δ ⊩ τ(p) true Δ ⊩ Σ A τ true pair p

slide-52
SLIDE 52

36

Dependent pairs

A type [] ⊩ A true τ(p) type Σ A τ type p

Logical relations: define predicate by recursion on representation of object-language type

∙ ⊩ A true Δ ⊩ τ(p) true Δ ⊩ Σ A τ true pair p

slide-53
SLIDE 53

37

Well-defined?

slide-54
SLIDE 54

37

  • 1. Simply-typed: Iterated inductive definition
  • Patterns defined first
  • Pattern-matching quantifies over them

Well-defined?

slide-55
SLIDE 55

37

  • 1. Simply-typed: Iterated inductive definition
  • Patterns defined first
  • Pattern-matching quantifies over them
  • 2. Dependent: Mutual definition
  • Patterns classified by types
  • Σ A τ quantifies over patterns

Well-defined?

slide-56
SLIDE 56

37

  • 1. Simply-typed: Iterated inductive definition
  • Patterns defined first
  • Pattern-matching quantifies over them
  • 2. Dependent: Mutual definition
  • Patterns classified by types
  • Σ A τ quantifies over patterns

Well-defined?

Why does this make sense?

slide-57
SLIDE 57

38

  • 1. Inductively define the syntax of positive types

A+ ::= A+ ⊗ B+ | 1 | A+ ⊕ B+ | 0 | ¬ A+

| nat | vec[p] | Σ A+ τ

  • 2. Simultaneously, recursively define patterns for A+

Δ ⊩ A ⊕ B =def= Either (Δ ⊩ A) (Δ ⊩ B)

Induction-Recursion

slide-58
SLIDE 58

39

Induction-Recursion

A type [] ⊩ A true τ(p) type Σ A τ type p

  • 1. Define the type A
  • 2. Define the patterns for A
  • 3. Define the types Σ A τ (quantifies over pats for A)
  • 4. Define the patterns for Σ A τ
  • 5. ...

τ quantifies over type A, which is smaller than Σ A τ

slide-59
SLIDE 59

40

Example

head :: (Σ nat (n ↦ vec[s n])) → bool

slide-60
SLIDE 60

40

Example

head :: (κ : bool false) ⊢ Σ nat (n ↦ vec[s n]) false head :: (Σ nat (n ↦ vec[s n])) → bool

...contrapositive...

slide-61
SLIDE 61

40

Example

head :: (κ : bool false) ⊢ Σ nat (n ↦ vec[s n]) false head :: (Σ nat (n ↦ vec[s n])) → bool

...contrapositive...

head :: Δ ⊩ Σ nat (n ↦ vec[s n]) true (κ : bool false), Δ ⊢ #

...one premise...

slide-62
SLIDE 62

41

Example

head (pair _ (cons x _)) ↦ throw x to κ (no case for head (pair n nil) !) head :: Δ ⊩ Σ nat (n ↦ vec[s n]) true (κ : bool false), Δ ⊢ #

slide-63
SLIDE 63

42

See Paper

Agda encoding Examples coded using Agda representation Discussion of type equality Types are equal iff they have the same patterns: induces an identity coercion (Σ A τ) = (Σ A’ τ’) : compare τ and τ’ extensionally

slide-64
SLIDE 64

43

Positively dependent types

  • 1. Extend higher-order focusing with

a simple form of dependency

  • 2. Formalize the language in Agda

Contributions:

slide-65
SLIDE 65

44

Positively dependent types

  • 1. Type and term levels share the same data
  • 2. But different notions of computation
  • Terms: Pattern-match results in E :: Γ ⊢ #

(can add effects to this judgement)

  • Types: Pattern-match τ results in types

(pure)

slide-66
SLIDE 66

45

Future work

Integrate with LICS work on variable binding Implement positively dependent types in GHC or ML Negatively dependent types, too?

slide-67
SLIDE 67

Thanks for listening!