Focusing on Binding and Computation Robert Harper Carnegie Mellon - - PowerPoint PPT Presentation

focusing on binding and computation
SMART_READER_LITE
LIVE PREVIEW

Focusing on Binding and Computation Robert Harper Carnegie Mellon - - PowerPoint PPT Presentation

Focusing on Binding and Computation Robert Harper Carnegie Mellon University (Joint work with Dan Licata and Noam Zeilberger) June 18, 2008 1 / 41 The Payload Main Results and Ideas Main Results and Ideas Motivation Focusing


slide-1
SLIDE 1

1 / 41

Focusing on Binding and Computation

Robert Harper Carnegie Mellon University (Joint work with Dan Licata and Noam Zeilberger)

June 18, 2008

slide-2
SLIDE 2

The Payload

The Payload

  • Main Results and

Ideas

  • Main Results and

Ideas Motivation Focusing Generalized Datatypes Conclusion

2 / 41

slide-3
SLIDE 3

Main Results and Ideas

The Payload

  • Main Results and

Ideas

  • Main Results and

Ideas Motivation Focusing Generalized Datatypes Conclusion

3 / 41

Integrate Logical Frameworks and Functional Programming.

  • LF level provides a generalized datatype mechanism adequate

for syntax, judgements, rules, proofs.

  • FP level provides the means to compute over these datatypes.

In this talk we restrict attention to simple (non-indexed) types (to appear, LICS 2008). Current work on extending to dependent types and indexed types (not to appear, ICFP 2008).

slide-4
SLIDE 4

Main Results and Ideas

The Payload

  • Main Results and

Ideas

  • Main Results and

Ideas Motivation Focusing Generalized Datatypes Conclusion

4 / 41

Polarized type systems.

  • Positive types are inductively defined by intro/focusing rules,

manipulated by elim/inversion rules.

  • Negative types are inductively defined by elim/inversion rules,

manipulated by intro/focusing rules. Contextual modal type systems.

  • ΨA has as elements “open terms” with parameters specified

by context Ψ.

  • Treats binding and scope without reliance on effects/state.
slide-5
SLIDE 5

Motivation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

5 / 41

slide-6
SLIDE 6

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

6 / 41

Goal: integrate representation and computation in a functional language. 1. Representation: types for syntax including binding and scope. 2. Computation: type of higher-order computations over these types.

slide-7
SLIDE 7

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

6 / 41

Goal: integrate representation and computation in a functional language. 1. Representation: types for syntax including binding and scope. 2. Computation: type of higher-order computations over these types. Requirements: 1. Sufficiently powerful to represent syntax, judgements, rules, proofs. 2. Sufficiently flexible to permit computation by structural induction modulo α-equivalence. 3. Purely functional, so that we may index types by syntax.

slide-8
SLIDE 8

Example: Domain-Specific Logics

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

7 / 41

Access control logic (excerpts):

sort : type. princ : sort. res : sort. term : sort => type. dan : term princ. bob : term princ. /home/dan/pub : term res. prop : type.

  • wns

: term princ => term res => prop. mayrd : term princ => term res => prop.

slide-9
SLIDE 9

Example: Domain-Specific Logics

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

8 / 41

Access control logic (excerpts):

true : prop => type. affirms : term princ => prop => type. impi : (imp A B) true <= (A true => B true). impe : B true <= A true <= (imp A B) true. aff : K affirms A <= A true. saysi : (K says A) true <= K affirms A. sayse : (K affirms C) <= (says K A) <= (K affirms A => K affirms C).

slide-10
SLIDE 10

Example: Domain-Specific Logics

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

9 / 41

Signature for proof-carrying access control:

type file[r:term res] val paper.tex : file[/home/dan/pub] type iam[p:term princ] val iambob : iam[bob] val read : ∀r.∀p.∀pf:atom (p mayrd r) true. file[r] -> iam[p] -> string

Implementation of read structurally analyzes proofs at run-time!

slide-11
SLIDE 11

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

10 / 41

There are two different function spaces in play here! 1. Representational: A ⇒ B (aka B ⇐ A). 2. Computational: A → B (aka B ← A). Representational functions:

slide-12
SLIDE 12

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

10 / 41

There are two different function spaces in play here! 1. Representational: A ⇒ B (aka B ⇐ A). 2. Computational: A → B (aka B ← A). Representational functions:

  • Adequate for syntax, rules, proofs.
slide-13
SLIDE 13

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

10 / 41

There are two different function spaces in play here! 1. Representational: A ⇒ B (aka B ⇐ A). 2. Computational: A → B (aka B ← A). Representational functions:

  • Adequate for syntax, rules, proofs.
  • Closed-ended: schemas built from parameters by composing

rules.

slide-14
SLIDE 14

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

10 / 41

There are two different function spaces in play here! 1. Representational: A ⇒ B (aka B ⇐ A). 2. Computational: A → B (aka B ← A). Representational functions:

  • Adequate for syntax, rules, proofs.
  • Closed-ended: schemas built from parameters by composing

rules. Computational functions:

slide-15
SLIDE 15

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

10 / 41

There are two different function spaces in play here! 1. Representational: A ⇒ B (aka B ⇐ A). 2. Computational: A → B (aka B ← A). Representational functions:

  • Adequate for syntax, rules, proofs.
  • Closed-ended: schemas built from parameters by composing

rules. Computational functions:

  • Compute by pattern matching.
slide-16
SLIDE 16

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

10 / 41

There are two different function spaces in play here! 1. Representational: A ⇒ B (aka B ⇐ A). 2. Computational: A → B (aka B ← A). Representational functions:

  • Adequate for syntax, rules, proofs.
  • Closed-ended: schemas built from parameters by composing

rules. Computational functions:

  • Compute by pattern matching.
  • Open-ended: any form of computation allowable.
slide-17
SLIDE 17

Derivability and Admissibility

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

11 / 41

Representational functions witness derivabilities, J1 ⊢ J2.

slide-18
SLIDE 18

Derivability and Admissibility

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

11 / 41

Representational functions witness derivabilities, J1 ⊢ J2.

  • J2 is derivable, taking J1 as a fresh axiom.
  • Evidence is uniform: λx:J1.M : J1 ⇒ J2.
slide-19
SLIDE 19

Derivability and Admissibility

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

11 / 41

Representational functions witness derivabilities, J1 ⊢ J2.

  • J2 is derivable, taking J1 as a fresh axiom.
  • Evidence is uniform: λx:J1.M : J1 ⇒ J2.

Computational functions witness admissibilities, J1 |

= J2.

slide-20
SLIDE 20

Derivability and Admissibility

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

11 / 41

Representational functions witness derivabilities, J1 ⊢ J2.

  • J2 is derivable, taking J1 as a fresh axiom.
  • Evidence is uniform: λx:J1.M : J1 ⇒ J2.

Computational functions witness admissibilities, J1 |

= J2.

  • Derivability of J1 implies derivability of J2.
  • Evidence is non-uniform: any function mapping derivations of J1

to derivations of J2.

slide-21
SLIDE 21

Derivability and Admissibility

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

11 / 41

Representational functions witness derivabilities, J1 ⊢ J2.

  • J2 is derivable, taking J1 as a fresh axiom.
  • Evidence is uniform: λx:J1.M : J1 ⇒ J2.

Computational functions witness admissibilities, J1 |

= J2.

  • Derivability of J1 implies derivability of J2.
  • Evidence is non-uniform: any function mapping derivations of J1

to derivations of J2. Side conditions correspond to rules that mix both forms:

¬(l ∈ dom(M)) (M, l) ⇑

i.e.

l ∈ dom(M) | =⊥ (M, l) ⇑

slide-22
SLIDE 22

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

12 / 41

Representational functions are

slide-23
SLIDE 23

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

12 / 41

Representational functions are

  • Introduced by composing rules from parameters.
slide-24
SLIDE 24

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

12 / 41

Representational functions are

  • Introduced by composing rules from parameters.
  • Eliminated by pattern matching / structural analysis.
slide-25
SLIDE 25

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

12 / 41

Representational functions are

  • Introduced by composing rules from parameters.
  • Eliminated by pattern matching / structural analysis.

Computational functions are

slide-26
SLIDE 26

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

12 / 41

Representational functions are

  • Introduced by composing rules from parameters.
  • Eliminated by pattern matching / structural analysis.

Computational functions are

  • Introduced by pattern matching / structural analysis.
slide-27
SLIDE 27

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

12 / 41

Representational functions are

  • Introduced by composing rules from parameters.
  • Eliminated by pattern matching / structural analysis.

Computational functions are

  • Introduced by pattern matching / structural analysis.
  • Eliminated by application to an argument.
slide-28
SLIDE 28

Representation and Computation

The Payload Motivation

  • Representation and

Computation

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Example:

Domain-Specific Logics

  • Representation and

Computation

  • Derivability and

Admissibility

  • Representation and

Computation Focusing Generalized Datatypes Conclusion

12 / 41

Representational functions are

  • Introduced by composing rules from parameters.
  • Eliminated by pattern matching / structural analysis.

Computational functions are

  • Introduced by pattern matching / structural analysis.
  • Eliminated by application to an argument.

Focusing provides a general framework for such dualities!

slide-29
SLIDE 29

Focusing

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

13 / 41

slide-30
SLIDE 30

Intro vs. Elim

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

14 / 41

Sums A ⊕ B:

slide-31
SLIDE 31

Intro vs. Elim

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

14 / 41

Sums A ⊕ B:

  • Introduced by choosing inl or inr
slide-32
SLIDE 32

Intro vs. Elim

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

14 / 41

Sums A ⊕ B:

  • Introduced by choosing inl or inr
  • Eliminated by pattern-matching
slide-33
SLIDE 33

Intro vs. Elim

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

14 / 41

Sums A ⊕ B:

  • Introduced by choosing inl or inr
  • Eliminated by pattern-matching

Computational functions A → B:

slide-34
SLIDE 34

Intro vs. Elim

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

14 / 41

Sums A ⊕ B:

  • Introduced by choosing inl or inr
  • Eliminated by pattern-matching

Computational functions A → B:

  • Introduced by pattern-matching on A
slide-35
SLIDE 35

Intro vs. Elim

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

14 / 41

Sums A ⊕ B:

  • Introduced by choosing inl or inr
  • Eliminated by pattern-matching

Computational functions A → B:

  • Introduced by pattern-matching on A
  • Eliminated by choosing an A to apply it to
slide-36
SLIDE 36

Positive vs. Negative Polarity

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

15 / 41

Sums A ⊕ B are positive:

  • Introduced by choosing inl or inr
  • Eliminated by pattern-matching

Computational functions A → B are negative:

  • Introduced by pattern-matching on A
  • Eliminated by choosing an A to apply it to
slide-37
SLIDE 37

Positive vs. Negative Polarity

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

15 / 41

Sums A ⊕ B are positive:

  • Introduced by choosing inl or inr
  • Eliminated by pattern-matching

Computational functions A → B are negative:

  • Introduced by pattern-matching on A
  • Eliminated by choosing an A to apply it to

Operationally: positive = eager, negative = lazy

slide-38
SLIDE 38

Focus vs. Inversion

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

16 / 41

Sums A ⊕ B are positive:

  • Introduced by choosing inl or inr
  • Eliminated by pattern-matching

Computational functions A → B are negative:

  • Introduced by pattern-matching on A
  • Eliminated by choosing an A to apply it to
slide-39
SLIDE 39

Focus vs. Inversion

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

16 / 41

Sums A ⊕ B are positive:

  • Introduced by choosing inl or inr
  • Eliminated by pattern-matching

Computational functions A → B are negative:

  • Introduced by pattern-matching on A
  • Eliminated by choosing an A to apply it to

Focus = make choices

slide-40
SLIDE 40

Focus vs. Inversion

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

17 / 41

Sums A ⊕ B are positive:

  • Introduced by choosing inl or inr
  • Eliminated by pattern-matching

Computational functions A → B are negative:

  • Introduced by pattern-matching on A
  • Eliminated by choosing an A to apply it to
slide-41
SLIDE 41

Focus vs. Inversion

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

17 / 41

Sums A ⊕ B are positive:

  • Introduced by choosing inl or inr
  • Eliminated by pattern-matching

Computational functions A → B are negative:

  • Introduced by pattern-matching on A
  • Eliminated by choosing an A to apply it to

Inversion = respond to all possible choices

slide-42
SLIDE 42

Polarity and Focusing

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

18 / 41

Positive type Negative type Intro Focus Inversion Elim Inversion Focus

slide-43
SLIDE 43

Higher-order Focusing

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

19 / 41

A concise way to define a language:

  • Specify a type by its focused behavior
  • Derive the inversion phase generically
slide-44
SLIDE 44

Polarized Type Theory

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

20 / 41

A concise way to define a language:

  • Specify a type by its focused behavior
  • Choices = patterns
  • Derive the inversion phase generically
  • Response = pattern matching
slide-45
SLIDE 45

Patterns for Positive Types

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

21 / 41

A+

::=

A+ ⊕ B + | A+ ⊗ B + | ↓A- A-

::=

A+ → B- | . . . ∆ p :: A+ ∆ inl p :: A+ ⊕ B + ∆ p :: B + ∆ inr p :: A+ ⊕ B +

slide-46
SLIDE 46

Patterns for Positive Types

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

21 / 41

A+

::=

A+ ⊕ B + | A+ ⊗ B + | ↓A- A-

::=

A+ → B- | . . . ∆ p :: A+ ∆ inl p :: A+ ⊕ B + ∆ p :: B + ∆ inr p :: A+ ⊕ B + ∆1 p1 :: A+ ∆2 p2 :: B + ∆1, ∆2 (p1, p2) :: A+ ⊗ B +

slide-47
SLIDE 47

Patterns for Positive Types

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

21 / 41

A+

::=

A+ ⊕ B + | A+ ⊗ B + | ↓A- A-

::=

A+ → B- | . . . ∆ p :: A+ ∆ inl p :: A+ ⊕ B + ∆ p :: B + ∆ inr p :: A+ ⊕ B + ∆1 p1 :: A+ ∆2 p2 :: B + ∆1, ∆2 (p1, p2) :: A+ ⊗ B + x : A- x :: ↓A-

slide-48
SLIDE 48

Positive Focus

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

22 / 41

  • positive value is pattern p with substitution σ
  • σ substitutes negative values v-/x for x : A- ∈ ∆

∆ p :: C + Γ ⊢ σ : ∆ Γ ⊢ p [σ] :: C +

slide-49
SLIDE 49

Positive Inversion

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

23 / 41

  • positive continuation is a case-analysis
  • specified by meta-level function φ = {p → e, . . .}

from patterns to expressions

∀(∆ p :: C +). Γ, ∆ ⊢ φ(p) : D + Γ ⊢ val+(φ) : C + > D +

slide-50
SLIDE 50

Example

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

24 / 41

Define

and* (true , true ) = true[·] and* (true , false) = false[·] and* (false , true ) = false[·] and* (false , false) = false[·]

Then · ⊢ val+(and*) : (bool ⊗ bool) > bool

slide-51
SLIDE 51

Negative Focus and Inversion is Dual

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

25 / 41

  • Continuation specified by destructor pattern (focus)
  • Value defined by pattern-matching φ (inversion)
slide-52
SLIDE 52

Negative Focus and Inversion is Dual

The Payload Motivation Focusing

  • Intro vs. Elim
  • Positive vs. Negative

Polarity

  • Focus vs. Inversion
  • Focus vs. Inversion
  • Polarity and Focusing
  • Higher-order

Focusing

  • Polarized Type

Theory

  • Patterns for Positive

Types

  • Positive Focus
  • Positive Inversion
  • Example
  • Negative Focus and

Inversion is Dual Generalized Datatypes Conclusion

25 / 41

  • Continuation specified by destructor pattern (focus)
  • Value defined by pattern-matching φ (inversion)

Simplification for this talk:

  • Equate Γ ⊢ v- : A+ → B + with Γ ⊢ k + : A+ > B +

e.g. · ⊢ add* : (bool ⊗ bool) → bool

  • Eliminated by choosing a value to apply it to
slide-53
SLIDE 53

Generalized Datatypes

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

26 / 41

slide-54
SLIDE 54

Datatypes

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

27 / 41

  • Class of datatypes P
  • Datatype constructors u specified by signature

Ψ = . . . , u : R, . . .

  • Rules R have the form P ⇐ A+

1 · · · ⇐ A+ n

(construct P from A+

1, . . . , A+ n)

Natural numbers:

Ψnat = zero : nat, succ : nat ⇐ nat

slide-55
SLIDE 55

Datatype Patterns

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

28 / 41

Add signature to pattern judgement: ∆ ; Ψ p :: A+

u : P ⇐ A+

1 · · · ⇐ A+ n ∈ Ψ

∆1 ; Ψ p1 :: A+

1

. . .

∆n ; Ψ pn :: A+

n

∆1, . . . , ∆n ; Ψ u p1 . . . pn :: P

slide-56
SLIDE 56

Datatype Continuations

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

29 / 41

Meta-functions φ now require infinitely many cases:

Ψnat = zero : nat, succ : nat ⇐ nat

To prove

Ψnat; · ⊢ val

+(double*) : nat > nat

STS

∀(∆ ; Ψnat p :: nat). Ψnat; ∆ ⊢ double*(p) : nat

slide-57
SLIDE 57

Datatype Continuations

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

30 / 41

∀(∆ ; Ψnat p :: nat). Ψnat; ∆ ⊢ double*(p) : nat double* 0 = 0 double* 1 = 2 double* 2 = 4 ...

Open-endedness: compatible with any concrete presentation of φ

slide-58
SLIDE 58

Contextual Hypotheses

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

31 / 41

Make hypotheses contextual:

::=

· | ∆, x : Ψ A- x : Ψ A- ; Ψ x :: ↓A-

Rule from before:

x : A- x :: ↓A-

slide-59
SLIDE 59

Contextual Continuations

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

32 / 41

Make continuations transform contextualized types:

∀(∆ ; Ψ p :: A+). Γ, ∆ ⊢ φ(p) : Ψ1 A+

1

Γ ⊢ val+(φ) : Ψ A+ > Ψ1 A+

1

Rule from before:

∀(∆ p :: C +). Γ, ∆ ⊢ φ(p) : D + Γ ⊢ val+(φ) : C + > D +

slide-60
SLIDE 60

Contextual Continuations

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

32 / 41

Make continuations transform contextualized types:

∀(∆ ; Ψ p :: A+). Γ, ∆ ⊢ φ(p) : Ψ1 A+

1

Γ ⊢ val+(φ) : Ψ A+ > Ψ1 A+

1

Rule from before:

∀(∆ p :: C +). Γ, ∆ ⊢ φ(p) : D + Γ ⊢ val+(φ) : C + > D +

Allows for types that manipulate Ψ . . .

slide-61
SLIDE 61

Representational Functions

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

33 / 41

Represent binding with a positive function space:

∆ ; Ψ, u : R p :: A+ ∆ ; Ψ λ u. p :: R ⇒ A+

  • Representational arrow R ⇒ A+ binds a

scoped datatype constructor

  • Pattern-matching gives induction over HOAS
slide-62
SLIDE 62

Example

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

34 / 41

e

::=

num[k] | e1 ⊙f e2 | let x = e1 in e2

Represent with a datatype ari:

zero : nat, succ : nat ⇐ nat, num : ari ⇐ nat binop : ari ⇐ ari ⇐ (nat ⊗ nat → nat) ⇐ ari let : ari ⇐ ari ⇐ (ari ⇒ ari)

slide-63
SLIDE 63

Example

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

35 / 41

Evaluator:

· ⊢ fix(ev.ev∗) : Ψari (ari → nat)

STS:

∀(∆ p :: Ψari ari). (ev : Ψari ari → nat, ∆) ⊢ (ev∗ p) : Ψari nat

slide-64
SLIDE 64

Example

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

36 / 41

∀(∆ p :: Ψari ari). (ev : Ψari ari → nat, ∆) ⊢ (ev∗ p) : Ψari nat

ev∗ (num p)

→ p

ev∗ (binop p1 f p2) → f (ev p1) (ev p2) ev∗ (let p0 (λ u. p)) → ev (apply (λ u. p, p0))

slide-65
SLIDE 65

Example

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

36 / 41

∀(∆ p :: Ψari ari). (ev : Ψari ari → nat, ∆) ⊢ (ev∗ p) : Ψari nat

ev∗ (num p)

→ p

ev∗ (binop p1 f p2) → f (ev p1) (ev p2) ev∗ (let p0 (λ u. p)) → ev (apply (λ u. p, p0)) What is apply?

slide-66
SLIDE 66

Substitution

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

37 / 41

apply : Ψ ((P ⇒ A) ⊗ P) → A

  • Just a program: not forced by the type theory
  • Should it always be defined?
slide-67
SLIDE 67

Substitution

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

37 / 41

apply : Ψ ((P ⇒ A) ⊗ P) → A

  • Just a program: not forced by the type theory
  • Should it always be defined?

Substitution requires weakening. . .

slide-68
SLIDE 68

Weakening

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

38 / 41

weaken : Ψ A → (P ⇒ A) Can you weaken

  • . . . an ari to ari ⇒ ari?
slide-69
SLIDE 69

Weakening

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

38 / 41

weaken : Ψ A → (P ⇒ A) Can you weaken

  • . . . an ari to ari ⇒ ari?

Hint: let : ari ⇐ ari ⇐ (ari ⇒ ari)

slide-70
SLIDE 70

Weakening

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

38 / 41

weaken : Ψ A → (P ⇒ A) Can you weaken

  • . . . an ari to ari ⇒ ari?

Hint: let : ari ⇐ ari ⇐ (ari ⇒ ari)

  • . . . a nat to ari ⇒ nat?
slide-71
SLIDE 71

Weakening

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

38 / 41

weaken : Ψ A → (P ⇒ A) Can you weaken

  • . . . an ari to ari ⇒ ari?

Hint: let : ari ⇐ ari ⇐ (ari ⇒ ari)

  • . . . a nat to ari ⇒ nat?
  • . . . an ari to nat ⇒ ari?
slide-72
SLIDE 72

Weakening

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

38 / 41

weaken : Ψ A → (P ⇒ A) Can you weaken

  • . . . an ari to ari ⇒ ari?

Hint: let : ari ⇐ ari ⇐ (ari ⇒ ari)

  • . . . a nat to ari ⇒ nat?
  • . . . an ari to nat ⇒ ari?

Hint: binop : ari ⇐ ari ⇐ (nat ⊗ nat → nat) ⇐ ari

slide-73
SLIDE 73

Structural Properties

The Payload Motivation Focusing Generalized Datatypes

  • Datatypes
  • Datatype Patterns
  • Datatype

Continuations

  • Datatype

Continuations

  • Contextual

Hypotheses

  • Contextual

Continuations

  • Representational

Functions

  • Example
  • Example
  • Example
  • Substitution
  • Weakening
  • Structural Properties

Conclusion

39 / 41

  • Structural properties hold when types are not circumscribed

(includes all LF rule systems)

  • Exploiting open-endedness, implement

apply, weaken, . . . once as datatype-generic programs at the meta-level

slide-74
SLIDE 74

Conclusion

The Payload Motivation Focusing Generalized Datatypes Conclusion

  • Conclusion

40 / 41

slide-75
SLIDE 75

Conclusion

The Payload Motivation Focusing Generalized Datatypes Conclusion

  • Conclusion

41 / 41

  • Logical framework for rules that mix ⇒ and →
  • Representation is positive
  • Computation is negative
  • Get structural properties “for free” under conditions

Otherwise you have to implement them, if they’re even true

  • Lots more to the story. . . (see LICS’08 paper and follow-ups).