church and curry: combining intrinsic and extrinsic typingfp/talks/andrewsfest12.pdfchurch and...

66
Church and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews on the occasion of his retirement Department of Computer Science Carnegie Mellon University April 5, 2012 1 / 24

Upload: others

Post on 06-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Church and Curry: Combining Intrinsic

and Extrinsic Typing

Frank Pfenning

Dedicated to Peter Andrewson the occasion of his retirement

Department of Computer ScienceCarnegie Mellon University

April 5, 2012

1 / 24

Page 2: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Church’s Simple Theory of Types

Language and logic for the formalization of mathematics

(Church 1940)Stood the test of time (72 years!)HOL, Isabelle/HOL, TPS, LEO, Satallax, . . .

Synthesis, simplification, and generalization of

Russell and Whitehead’s ramified theory of typesChurch and Rosser’s (untyped) λ-calculus

Some objections

As a computer scientist: classicalAs a philosopher: impredicative

Components

Simply typed λ-calculus (this talk)Logical axioms and inference rules

2 / 24

Page 3: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Church’s Simple Theory of Types

Language and logic for the formalization of mathematics

(Church 1940)Stood the test of time (72 years!)HOL, Isabelle/HOL, TPS, LEO, Satallax, . . .

Synthesis, simplification, and generalization of

Russell and Whitehead’s ramified theory of typesChurch and Rosser’s (untyped) λ-calculus

Some objections

As a computer scientist: classicalAs a philosopher: impredicative

Components

Simply typed λ-calculus (this talk)Logical axioms and inference rules

2 / 24

Page 4: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Church’s Simple Theory of Types

Language and logic for the formalization of mathematics

(Church 1940)Stood the test of time (72 years!)HOL, Isabelle/HOL, TPS, LEO, Satallax, . . .

Synthesis, simplification, and generalization of

Russell and Whitehead’s ramified theory of typesChurch and Rosser’s (untyped) λ-calculus

Some objections

As a computer scientist: classicalAs a philosopher: impredicative

Components

Simply typed λ-calculus (this talk)Logical axioms and inference rules

2 / 24

Page 5: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Church’s Simple Theory of Types

Language and logic for the formalization of mathematics

(Church 1940)Stood the test of time (72 years!)HOL, Isabelle/HOL, TPS, LEO, Satallax, . . .

Synthesis, simplification, and generalization of

Russell and Whitehead’s ramified theory of typesChurch and Rosser’s (untyped) λ-calculus

Some objections

As a computer scientist: classical

As a philosopher: impredicative

Components

Simply typed λ-calculus (this talk)Logical axioms and inference rules

2 / 24

Page 6: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Church’s Simple Theory of Types

Language and logic for the formalization of mathematics

(Church 1940)Stood the test of time (72 years!)HOL, Isabelle/HOL, TPS, LEO, Satallax, . . .

Synthesis, simplification, and generalization of

Russell and Whitehead’s ramified theory of typesChurch and Rosser’s (untyped) λ-calculus

Some objections

As a computer scientist: classicalAs a philosopher: impredicative

Components

Simply typed λ-calculus (this talk)Logical axioms and inference rules

2 / 24

Page 7: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Church’s Simple Theory of Types

Language and logic for the formalization of mathematics

(Church 1940)Stood the test of time (72 years!)HOL, Isabelle/HOL, TPS, LEO, Satallax, . . .

Synthesis, simplification, and generalization of

Russell and Whitehead’s ramified theory of typesChurch and Rosser’s (untyped) λ-calculus

Some objections

As a computer scientist: classicalAs a philosopher: impredicative

Components

Simply typed λ-calculus (this talk)Logical axioms and inference rules

2 / 24

Page 8: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Church’s Simple Theory of Types

Language and logic for the formalization of mathematics

(Church 1940)Stood the test of time (72 years!)HOL, Isabelle/HOL, TPS, LEO, Satallax, . . .

Synthesis, simplification, and generalization of

Russell and Whitehead’s ramified theory of typesChurch and Rosser’s (untyped) λ-calculus

Some objections

As a computer scientist: classicalAs a philosopher: impredicative

Components

Simply typed λ-calculus (this talk)Logical axioms and inference rules

2 / 24

Page 9: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Simply Typed λ-Calculus

Church’s definitions

Types

1 ι and o are types.2 If α and β are types, then α→ β is a type.

(Church wrote βα)

Well-formed terms Mα of type α

1 Any variable xα or constant cα is a term.2 If xα is a variable and Mβ a term then (λx .M)α→β is a

term.3 If Mα→β

1 and Mα2 are terms, then (M1M2)β is a term.

3 / 24

Page 10: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Simply Typed λ-Calculus

Church’s definitions

Types

1 ι and o are types.2 If α and β are types, then α→ β is a type.

(Church wrote βα)

Well-formed terms Mα of type α

1 Any variable xα or constant cα is a term.2 If xα is a variable and Mβ a term then (λx .M)α→β is a

term.3 If Mα→β

1 and Mα2 are terms, then (M1M2)β is a term.

3 / 24

Page 11: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Simply Typed λ-Calculus

Church’s definitions

Types

1 ι and o are types.2 If α and β are types, then α→ β is a type.

(Church wrote βα)

Well-formed terms Mα of type α

1 Any variable xα or constant cα is a term.2 If xα is a variable and Mβ a term then (λx .M)α→β is a

term.3 If Mα→β

1 and Mα2 are terms, then (M1M2)β is a term.

3 / 24

Page 12: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Intrinsic Typing

Every well-formed term has an intrinsic type, includingvariables

This kind of intrinsic formulation has become rare, but ithas a number of advantages

Supports conventions, such as

In the remainder of this [talk] we assume thatall terms are well-formed according to the abovedefinition.

In a logical framework

tp : type.

arrow : tp -> tp -> tp.

tm : tp -> type.

lam : (tm A -> tm B) -> tm (arrow A B).

app : tm (arrow A B) -> tm A -> tm B.

4 / 24

Page 13: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Intrinsic Typing

Every well-formed term has an intrinsic type, includingvariables

This kind of intrinsic formulation has become rare, but ithas a number of advantages

Supports conventions, such as

In the remainder of this [talk] we assume thatall terms are well-formed according to the abovedefinition.

In a logical framework

tp : type.

arrow : tp -> tp -> tp.

tm : tp -> type.

lam : (tm A -> tm B) -> tm (arrow A B).

app : tm (arrow A B) -> tm A -> tm B.

4 / 24

Page 14: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Intrinsic Typing

Every well-formed term has an intrinsic type, includingvariables

This kind of intrinsic formulation has become rare, but ithas a number of advantages

Supports conventions, such as

In the remainder of this [talk] we assume thatall terms are well-formed according to the abovedefinition.

In a logical framework

tp : type.

arrow : tp -> tp -> tp.

tm : tp -> type.

lam : (tm A -> tm B) -> tm (arrow A B).

app : tm (arrow A B) -> tm A -> tm B.

4 / 24

Page 15: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Intrinsic Typing

Every well-formed term has an intrinsic type, includingvariables

This kind of intrinsic formulation has become rare, but ithas a number of advantages

Supports conventions, such as

In the remainder of this [talk] we assume thatall terms are well-formed according to the abovedefinition.

In a logical framework

tp : type.

arrow : tp -> tp -> tp.

tm : tp -> type.

lam : (tm A -> tm B) -> tm (arrow A B).

app : tm (arrow A B) -> tm A -> tm B.

4 / 24

Page 16: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Untyped λ-Calculus

(Church 1932) (Church and Rosser 1936)

Terms

1 Any variable x or constant c is a term.2 If x is a variable and M a term then (λx .M) is a term.3 If M1 and M2 are terms, then (M1M2) is a term.

5 / 24

Page 17: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Extrinsic Typing

(Curry 1934) [for combinators, not λ-terms]

Types as properties of terms

Typing judgments defined by rules

x :α ∈ Γ

Γ ` x : α

c :α ∈ Σ

Γ ` c : α

Γ, x :α ` M : β (x 6∈ dom(Γ))

Γ ` λx .M : α→ β

Γ ` M : α→ β Γ ` N : α

Γ ` M N : β

6 / 24

Page 18: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Extrinsic Typing

(Curry 1934) [for combinators, not λ-terms]

Types as properties of terms

Typing judgments defined by rules

x :α ∈ Γ

Γ ` x : α

c :α ∈ Σ

Γ ` c : α

Γ, x :α ` M : β (x 6∈ dom(Γ))

Γ ` λx .M : α→ β

Γ ` M : α→ β Γ ` N : α

Γ ` M N : β

6 / 24

Page 19: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Types as Properties

A term can have multiple types

· ` λx . x : ι→ ι· ` λx . x : (ι→ ι)→ (ι→ ι)

Express explicitly in the form of a single type

Parametric polymorphism (universal types)

· ` λx . x : ∀t. t → t

Ad hoc polymorphism (intersection types)

· ` λx . x : (ι→ ι) ∧ ((ι→ ι)→ (ι→ ι))

7 / 24

Page 20: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Types as Properties

A term can have multiple types

· ` λx . x : ι→ ι· ` λx . x : (ι→ ι)→ (ι→ ι)

Express explicitly in the form of a single type

Parametric polymorphism (universal types)

· ` λx . x : ∀t. t → t

Ad hoc polymorphism (intersection types)

· ` λx . x : (ι→ ι) ∧ ((ι→ ι)→ (ι→ ι))

7 / 24

Page 21: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Types as Properties

A term can have multiple types

· ` λx . x : ι→ ι· ` λx . x : (ι→ ι)→ (ι→ ι)

Express explicitly in the form of a single type

Parametric polymorphism (universal types)

· ` λx . x : ∀t. t → t

Ad hoc polymorphism (intersection types)

· ` λx . x : (ι→ ι) ∧ ((ι→ ι)→ (ι→ ι))

7 / 24

Page 22: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Types as Properties

A term can have multiple types

· ` λx . x : ι→ ι· ` λx . x : (ι→ ι)→ (ι→ ι)

Express explicitly in the form of a single type

Parametric polymorphism (universal types)

· ` λx . x : ∀t. t → t

Ad hoc polymorphism (intersection types)

· ` λx . x : (ι→ ι) ∧ ((ι→ ι)→ (ι→ ι))

7 / 24

Page 23: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Extrinsic Rules

Parametric polymorphism

Γ ` M : β (t 6∈ ftv(Γ))

Γ ` M : ∀t. β∀I

Γ ` M : ∀t. α

Γ ` M : [β/t]α∀E

Intersection polymorphism

Γ ` M : A Γ ` M : B

Γ ` M : A ∧ B∧I

Γ ` M : A ∧ B

Γ ` M : A∧E1

Γ ` M : A ∧ B

Γ ` M : B∧E2

8 / 24

Page 24: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Extrinsic Rules

Parametric polymorphism

Γ ` M : β (t 6∈ ftv(Γ))

Γ ` M : ∀t. β∀I

Γ ` M : ∀t. α

Γ ` M : [β/t]α∀E

Intersection polymorphism

Γ ` M : A Γ ` M : B

Γ ` M : A ∧ B∧I

Γ ` M : A ∧ B

Γ ` M : A∧E1

Γ ` M : A ∧ B

Γ ` M : B∧E2

8 / 24

Page 25: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Types as Properties: The Good News

Can type terms more generally

· ` λx . x x : (∀α. α→ α)→ (∀β. β → β)· ` λx . x x : ((ι→ ι) ∧ ι)→ ι

Can type type terms more accurately

· ` λx . s(s(s x)) : (even→ odd) ∧ (odd→ even)

9 / 24

Page 26: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Types as Properties: The Good News

Can type terms more generally

· ` λx . x x : (∀α. α→ α)→ (∀β. β → β)· ` λx . x x : ((ι→ ι) ∧ ι)→ ι

Can type type terms more accurately

· ` λx . s(s(s x)) : (even→ odd) ∧ (odd→ even)

9 / 24

Page 27: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Types as Properties: The Bad News

The typing judgment is undecidable

Challenge: generalize to a complete language

PracticalUsefulPhilosophically justifiedEasy to reason about

10 / 24

Page 28: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Types as Properties: The Bad News

The typing judgment is undecidable

Challenge: generalize to a complete language

PracticalUsefulPhilosophically justifiedEasy to reason about

10 / 24

Page 29: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Layering Type Systems

Intrinsic simple types for basic consistency

Avoiding Russell’s paradox

Extrinsic sorts on well-formed terms for precision

Circumvent problems with general extrinsic typesAchieve pragmatic goals

Instances

Intersection types to datasort refinement (this talk)Dependent types to index refinements

Parametric polymorphism is a different story

11 / 24

Page 30: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Layering Type Systems

Intrinsic simple types for basic consistency

Avoiding Russell’s paradox

Extrinsic sorts on well-formed terms for precision

Circumvent problems with general extrinsic typesAchieve pragmatic goals

Instances

Intersection types to datasort refinement (this talk)Dependent types to index refinements

Parametric polymorphism is a different story

11 / 24

Page 31: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Layering Type Systems

Intrinsic simple types for basic consistency

Avoiding Russell’s paradox

Extrinsic sorts on well-formed terms for precision

Circumvent problems with general extrinsic typesAchieve pragmatic goals

Instances

Intersection types to datasort refinement (this talk)Dependent types to index refinements

Parametric polymorphism is a different story

11 / 24

Page 32: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Layering Type Systems

Intrinsic simple types for basic consistency

Avoiding Russell’s paradox

Extrinsic sorts on well-formed terms for precision

Circumvent problems with general extrinsic typesAchieve pragmatic goals

Instances

Intersection types to datasort refinement (this talk)Dependent types to index refinements

Parametric polymorphism is a different story

11 / 24

Page 33: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Representing Data

Multiple techniques in Church’s Type Theory

Church numeralsConstants and axioms

We have only basic type ι (o is for truth values)

Example: natural numbers

Constants zι and sι→ι (constructors)Constant natι→o (predicate)Axioms

nat(z)∀x ι. nat(x) ⊃ nat(s(x))

Lists, trees, etc. all have type ι

Sort out using sorts

12 / 24

Page 34: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Representing Data

Multiple techniques in Church’s Type Theory

Church numeralsConstants and axioms

We have only basic type ι (o is for truth values)

Example: natural numbers

Constants zι and sι→ι (constructors)Constant natι→o (predicate)Axioms

nat(z)∀x ι. nat(x) ⊃ nat(s(x))

Lists, trees, etc. all have type ι

Sort out using sorts

12 / 24

Page 35: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Representing Data

Multiple techniques in Church’s Type Theory

Church numeralsConstants and axioms

We have only basic type ι (o is for truth values)

Example: natural numbers

Constants zι and sι→ι (constructors)Constant natι→o (predicate)Axioms

nat(z)∀x ι. nat(x) ⊃ nat(s(x))

Lists, trees, etc. all have type ι

Sort out using sorts

12 / 24

Page 36: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Representing Data

Multiple techniques in Church’s Type Theory

Church numeralsConstants and axioms

We have only basic type ι (o is for truth values)

Example: natural numbers

Constants zι and sι→ι (constructors)Constant natι→o (predicate)Axioms

nat(z)∀x ι. nat(x) ⊃ nat(s(x))

Lists, trees, etc. all have type ι

Sort out using sorts

12 / 24

Page 37: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Simple Sorts

Examplenatι sortzι : natsι→ι : nat→ nat

Define sorts Sα refining type α under signature Σ

1 A base sort Qι declared in Σ is a simple sort.2 If Sα and T β are simple sorts, then (S → T )α→β is a

simple sort.

13 / 24

Page 38: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Simple Sorts

Examplenatι sortzι : natsι→ι : nat→ nat

Define sorts Sα refining type α under signature Σ

1 A base sort Qι declared in Σ is a simple sort.2 If Sα and T β are simple sorts, then (S → T )α→β is a

simple sort.

13 / 24

Page 39: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Sorting Judgment

Context Γ consisting of declarations xα : Sα

Sorting judgment Γ ` Mα : Sα

Defined only for terms of intrinsic type α and sort refiningthe same type α!

Rulesx :S ∈ Γ

Γ ` x : S

c :S ∈ Σ

Γ ` c : S

Γ, x :S ` M : T (x 6∈ dom(Γ))

Γ ` λx .M : S → T

Γ ` M : S → T Γ ` N : S

Γ ` M N : T

14 / 24

Page 40: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Sorting Judgment

Context Γ consisting of declarations xα : Sα

Sorting judgment Γ ` Mα : Sα

Defined only for terms of intrinsic type α and sort refiningthe same type α!

Rulesx :S ∈ Γ

Γ ` x : S

c :S ∈ Σ

Γ ` c : S

Γ, x :S ` M : T (x 6∈ dom(Γ))

Γ ` λx .M : S → T

Γ ` M : S → T Γ ` N : S

Γ ` M N : T

14 / 24

Page 41: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Sorting Judgment

Context Γ consisting of declarations xα : Sα

Sorting judgment Γ ` Mα : Sα

Defined only for terms of intrinsic type α and sort refiningthe same type α!

Rulesx :S ∈ Γ

Γ ` x : S

c :S ∈ Σ

Γ ` c : S

Γ, x :S ` M : T (x 6∈ dom(Γ))

Γ ` λx .M : S → T

Γ ` M : S → T Γ ` N : S

Γ ` M N : T

14 / 24

Page 42: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Subsorts

Subsort declarations Q ι1 ≤ Q ι

2

New rules

Q ≤ Q

Q1 ≤ Q2 Q2 ≤ Q3

Q1 ≤ Q3

Γ ` M : Q Q ≤ Q ′

Γ ` M : Q ′

Defined on base types only

Can derive principles for higher types

15 / 24

Page 43: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Subsorting Example

Refining natural numbers

zero ≤ natpos ≤ natz : zeros : nat→ pos

Examples

· ` λx . x : nat→ nat· ` λx . x : zero→ nat· ` λx . λy . x y : (nat→ zero)→ (zero→ nat)· ` λx . s x : nat→ pos

16 / 24

Page 44: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Subsorting Example

Refining natural numbers

zero ≤ natpos ≤ natz : zeros : nat→ pos

Examples

· ` λx . x : nat→ nat· ` λx . x : zero→ nat· ` λx . λy . x y : (nat→ zero)→ (zero→ nat)· ` λx . s x : nat→ pos

16 / 24

Page 45: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Combining Properties

Want to express and exploit multiple properties of terms

Example: even and odd numbers

even ≤ natodd ≤ natz : evens : even→ odds : odd→ even

Have no way to express in one sort:

· ` λx ι. s(s(s x)) : even→ odd· ` λx ι. s(s(s x)) : odd→ even

17 / 24

Page 46: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Combining Properties

Want to express and exploit multiple properties of terms

Example: even and odd numbers

even ≤ natodd ≤ natz : evens : even→ odds : odd→ even

Have no way to express in one sort:

· ` λx ι. s(s(s x)) : even→ odd· ` λx ι. s(s(s x)) : odd→ even

17 / 24

Page 47: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Combining Properties

Want to express and exploit multiple properties of terms

Example: even and odd numbers

even ≤ natodd ≤ natz : evens : even→ odds : odd→ even

Have no way to express in one sort:

· ` λx ι. s(s(s x)) : even→ odd· ` λx ι. s(s(s x)) : odd→ even

17 / 24

Page 48: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Intersection Sorts

Define sorts Sα refining types α (in intrinsic style)

1 A base sort Qι declared in Σ is a sort.2 If Sα and T β are sorts, then (S → T )α→β is a sort.3 If Sα and Tα are sorts then (S ∧ T )α is a sort.4 >α is a sort for each type α.

18 / 24

Page 49: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Extended Sorting Judgments

Recall Γ ` Mα : Sα

New typing rules

Γ ` M : S1 Γ ` M : S2

Γ ` M : S1 ∧ S2∧I

Γ ` M : S1 ∧ S2

Γ ` M : S1

∧E1

Γ ` M : S1 ∧ S2

Γ ` M : S2

∧E2

Γ ` M : > >I

Philosophically justified in the sense ofDummett/Martin-Lof

19 / 24

Page 50: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Extended Sorting Judgments

Recall Γ ` Mα : Sα

New typing rules

Γ ` M : S1 Γ ` M : S2

Γ ` M : S1 ∧ S2∧I

Γ ` M : S1 ∧ S2

Γ ` M : S1

∧E1

Γ ` M : S1 ∧ S2

Γ ` M : S2

∧E2

Γ ` M : > >I

Philosophically justified in the sense ofDummett/Martin-Lof

19 / 24

Page 51: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Extended Sorting Judgments

Recall Γ ` Mα : Sα

New typing rules

Γ ` M : S1 Γ ` M : S2

Γ ` M : S1 ∧ S2∧I

Γ ` M : S1 ∧ S2

Γ ` M : S1

∧E1

Γ ` M : S1 ∧ S2

Γ ` M : S2

∧E2

Γ ` M : > >I

Philosophically justified in the sense ofDummett/Martin-Lof

19 / 24

Page 52: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Example Revisited

Can now conjoin properties

· ` λx ι. s(s(s x)) : (even→ odd)∧ (odd→ even)∧ (nat→ pos)∧ . . .

Every (well-formed) term has a principal sort

20 / 24

Page 53: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Example Revisited

Can now conjoin properties

· ` λx ι. s(s(s x)) : (even→ odd)∧ (odd→ even)∧ (nat→ pos)∧ . . .

Every (well-formed) term has a principal sort

20 / 24

Page 54: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Some Results

Sort checking is decidable

“Proof:” there are effectively only finitely manyrefinements of a given type

Sorting is closed under β-reduction

“Proof:” standard substitution property

Sorting is closed under η-expansion

“Proof:” induction over sorts

21 / 24

Page 55: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Some Results

Sort checking is decidable

“Proof:” there are effectively only finitely manyrefinements of a given type

Sorting is closed under β-reduction

“Proof:” standard substitution property

Sorting is closed under η-expansion

“Proof:” induction over sorts

21 / 24

Page 56: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Some Results

Sort checking is decidable

“Proof:” there are effectively only finitely manyrefinements of a given type

Sorting is closed under β-reduction

“Proof:” standard substitution property

Sorting is closed under η-expansion

“Proof:” induction over sorts

21 / 24

Page 57: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

More Results

Define ηα(M) as η-long form of Mα

Define subsorting Sα ≤ Tα at higher types

S ≤ T :⇔ x :S ` ηα(x) : T

Extend subsumption rule

Sorting is closed under β-expansion

“Proof:” intersect all sorts the abstracted term is used at

Sorting is closed under η-reduction

“Proof:” by subsorting at higher types

ConclusionExtrinsic (Curry) sorting with intersectionsrefining intrinsic (Church) typing is closed underλ-conversion!

22 / 24

Page 58: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

More Results

Define ηα(M) as η-long form of Mα

Define subsorting Sα ≤ Tα at higher types

S ≤ T :⇔ x :S ` ηα(x) : T

Extend subsumption rule

Sorting is closed under β-expansion

“Proof:” intersect all sorts the abstracted term is used at

Sorting is closed under η-reduction

“Proof:” by subsorting at higher types

ConclusionExtrinsic (Curry) sorting with intersectionsrefining intrinsic (Church) typing is closed underλ-conversion!

22 / 24

Page 59: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

More Results

Define ηα(M) as η-long form of Mα

Define subsorting Sα ≤ Tα at higher types

S ≤ T :⇔ x :S ` ηα(x) : T

Extend subsumption rule

Sorting is closed under β-expansion

“Proof:” intersect all sorts the abstracted term is used at

Sorting is closed under η-reduction

“Proof:” by subsorting at higher types

ConclusionExtrinsic (Curry) sorting with intersectionsrefining intrinsic (Church) typing is closed underλ-conversion!

22 / 24

Page 60: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

More Results

Define ηα(M) as η-long form of Mα

Define subsorting Sα ≤ Tα at higher types

S ≤ T :⇔ x :S ` ηα(x) : T

Extend subsumption rule

Sorting is closed under β-expansion

“Proof:” intersect all sorts the abstracted term is used at

Sorting is closed under η-reduction

“Proof:” by subsorting at higher types

ConclusionExtrinsic (Curry) sorting with intersectionsrefining intrinsic (Church) typing is closed underλ-conversion!

22 / 24

Page 61: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

More Results

Define ηα(M) as η-long form of Mα

Define subsorting Sα ≤ Tα at higher types

S ≤ T :⇔ x :S ` ηα(x) : T

Extend subsumption rule

Sorting is closed under β-expansion

“Proof:” intersect all sorts the abstracted term is used at

Sorting is closed under η-reduction

“Proof:” by subsorting at higher types

ConclusionExtrinsic (Curry) sorting with intersectionsrefining intrinsic (Church) typing is closed underλ-conversion!

22 / 24

Page 62: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

More Results

Define ηα(M) as η-long form of Mα

Define subsorting Sα ≤ Tα at higher types

S ≤ T :⇔ x :S ` ηα(x) : T

Extend subsumption rule

Sorting is closed under β-expansion

“Proof:” intersect all sorts the abstracted term is used at

Sorting is closed under η-reduction

“Proof:” by subsorting at higher types

ConclusionExtrinsic (Curry) sorting with intersectionsrefining intrinsic (Church) typing is closed underλ-conversion!

22 / 24

Page 63: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Related Developments (my students only)

Expressive power extends tree automata to higher types

Canonical (= β-normal, η-long) terms can by typedbidirectionally

In: Festschrift in Honor of Peter B. Andrews on his 70thBirthday, C. Benzmuller, C. Brown, J. Siekmann, and R.Statman, editorsCrucial for logical frameworks (Lovas 2010)

Refinement type inference for ML (Freeman 1994)

Practical refinements type for SML (Davies 2005)

Dependent refinements over decidable domains (Xi 1998)

Unifying sort and dependent refinements (Dunfield 2007)

23 / 24

Page 64: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Conclusion

Church’s original intrinsic formulation of the simply-typedλ-calculus has fallen into disfavor, perhaps unjustly

It suggests an elegant layering with Curry’s extrinsictyping judgment (translated to λ-calculus)

Can be usefully combined with Coppo et al.’s intersectiontypes for high expressiveness, precision, and surprisinglystrong metatheoretic results

24 / 24

Page 65: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Conclusion

Church’s original intrinsic formulation of the simply-typedλ-calculus has fallen into disfavor, perhaps unjustly

It suggests an elegant layering with Curry’s extrinsictyping judgment (translated to λ-calculus)

Can be usefully combined with Coppo et al.’s intersectiontypes for high expressiveness, precision, and surprisinglystrong metatheoretic results

24 / 24

Page 66: Church and Curry: Combining Intrinsic and Extrinsic Typingfp/talks/andrewsfest12.pdfChurch and Curry: Combining Intrinsic and Extrinsic Typing Frank Pfenning Dedicated to Peter Andrews

Conclusion

Church’s original intrinsic formulation of the simply-typedλ-calculus has fallen into disfavor, perhaps unjustly

It suggests an elegant layering with Curry’s extrinsictyping judgment (translated to λ-calculus)

Can be usefully combined with Coppo et al.’s intersectiontypes for high expressiveness, precision, and surprisinglystrong metatheoretic results

24 / 24