Professional Documents
Culture Documents
revisited
Curry-Howard
Martin-Löf’s Type Theory correspondence
Martin-Löf’s type
theory
October 6, 2010
1
Outline
Type systems:
revisited
Curry-Howard
Type systems: revisited correspondence
Martin-Löf’s type
theory
Curry-Howard correspondence
2
Outline
Type systems:
revisited
Curry-Howard
Type systems: revisited correspondence
Martin-Löf’s type
theory
Curry-Howard correspondence
3
Why type systems?
Type systems:
revisited
Curry-Howard
correspondence
Martin-Löf’s type
theory
4
Why type systems?
4
Why type systems?
4
Why type systems?
4
Why type systems?
4
Why type systems?
4
Type checking
Type systems:
revisited
Curry-Howard
I Type checking of terms is done automatically by the correspondence
5
Type checking
Type systems:
revisited
Curry-Howard
I Type checking of terms is done automatically by the correspondence
5
Types and terms
Type systems:
revisited
Curry-Howard
correspondence
6
Types and terms
Type systems:
revisited
Curry-Howard
correspondence
6
Terms
t : : = true Curry-Howard
correspondence
false Martin-Löf’s type
i f t then t e l s e t theory
0
succ t
pred t
t + t
iszero t
7
Terms
t : : = true Curry-Howard
correspondence
false Martin-Löf’s type
i f t then t e l s e t theory
0
succ t
pred t
t + t
iszero t
And we want to be able to use a set of variables: {x, y, x1 , ...}
representing arbitrary terms.
7
Types
Type systems:
revisited
Curry-Howard
correspondence
Martin-Löf’s type
Types of this example arithmetic language: theory
T : : = Bool
Nat
8
Typing simple expressions
Type systems:
revisited
Curry-Howard
So now we can already type most of our expressions. For correspondence
Martin-Löf’s type
example: theory
9
Typing simple expressions
Type systems:
revisited
Curry-Howard
So now we can already type most of our expressions. For correspondence
Martin-Löf’s type
example: theory
3 : Nat
9
Typing simple expressions
Type systems:
revisited
Curry-Howard
So now we can already type most of our expressions. For correspondence
Martin-Löf’s type
example: theory
3 : Nat
(if true then 4 else 5) : Nat.
9
Typing simple expressions
Type systems:
revisited
Curry-Howard
So now we can already type most of our expressions. For correspondence
Martin-Löf’s type
example: theory
3 : Nat
(if true then 4 else 5) : Nat.
succ true will not be correctly typed.
9
Environments (contexts) (1)
Type systems:
But before we’re able to fully construct a typing relation we revisited
Curry-Howard
would need to be able to type expression like these: correspondence
Martin-Löf’s type
theory
10
Environments (contexts) (1)
Type systems:
But before we’re able to fully construct a typing relation we revisited
Curry-Howard
would need to be able to type expression like these: correspondence
Martin-Löf’s type
x + 3, theory
if x then 3 else 5,
etc.
10
Environments (contexts) (1)
Type systems:
But before we’re able to fully construct a typing relation we revisited
Curry-Howard
would need to be able to type expression like these: correspondence
Martin-Löf’s type
x + 3, theory
if x then 3 else 5,
etc.
10
Environments (contexts) (2)
Type systems:
revisited
Curry-Howard
correspondence
An environment can be build up by starting with the empty Martin-Löf’s type
theory
environment and by adding bindings.
11
Environments (contexts) (2)
Type systems:
revisited
Curry-Howard
correspondence
An environment can be build up by starting with the empty Martin-Löf’s type
theory
environment and by adding bindings.
Γ ::=
| Γ ,x : T
11
Typing relation
Martin-Löf’s type
theory
12
Typing relation
Γ `t :T Martin-Löf’s type
theory
12
Typing relation
Γ `t :T Martin-Löf’s type
theory
12
Typing relation
Γ `t :T Martin-Löf’s type
theory
12
Type rules
Type systems:
revisited
I To construct the typing relation we use type rules in Curry-Howard
Gentzen style natural deduction. correspondence
Martin-Löf’s type
I Inference rules come in two forms, with and without theory
assumptions.
13
Type rules
Type systems:
revisited
I To construct the typing relation we use type rules in Curry-Howard
Gentzen style natural deduction. correspondence
Martin-Löf’s type
I Inference rules come in two forms, with and without theory
assumptions.
Γ `M :Nat Γ `N :Nat
Γ `M +N :Nat (inference rule)
13
Outline
Type systems:
revisited
Curry-Howard
Type systems: revisited correspondence
Martin-Löf’s type
theory
Curry-Howard correspondence
14
Lambda calculus and natural deduction(1)
Type systems:
Assuming a simply-typed lambda calculus, some standard revisited
Curry-Howard
type (inference) rules would be: correspondence
Martin-Löf’s type
theory
15
Lambda calculus and natural deduction(1)
Type systems:
Assuming a simply-typed lambda calculus, some standard revisited
Curry-Howard
type (inference) rules would be: correspondence
Martin-Löf’s type
Γ ,x:α`t:β theory
Γ1 ,x:α,Γ2 `x:α (axiom) Γ `λx.t:α→β (function abstraction)
Γ `t:α→β Γ `u:α
Γ `t u:β (function application)
15
Lambda calculus and natural deduction(1)
Type systems:
Assuming a simply-typed lambda calculus, some standard revisited
Curry-Howard
type (inference) rules would be: correspondence
Martin-Löf’s type
Γ ,x:α`t:β theory
Γ1 ,x:α,Γ2 `x:α (axiom) Γ `λx.t:α→β (function abstraction)
Γ `t:α→β Γ `u:α
Γ `t u:β (function application)
15
Lambda calculus and natural deduction(2)
I Lambda calculus:
Type systems:
revisited
Γ ,x:α`t:β
Γ1 ,x:α,Γ2 `x:α (axiom) Γ `λx.t:α→β (function abstraction)
Curry-Howard
correspondence
Martin-Löf’s type
theory
Γ `t:α→β Γ `u:α
Γ `t u:β (function application)
16
Lambda calculus and natural deduction(2)
I Lambda calculus:
Type systems:
revisited
Γ ,x:α`t:β
Γ1 ,x:α,Γ2 `x:α (axiom) Γ `λx.t:α→β (function abstraction)
Curry-Howard
correspondence
Martin-Löf’s type
theory
Γ `t:α→β Γ `u:α
Γ `t u:β (function application)
Γ ,α`β
Γ1 ,α,Γ2 `α (axiom) Γ `α→β (→ introduction)
Γ `α→β Γ `α
Γ `β (→ elimination)
16
Curry-Howard correspondence (1)
Type systems:
revisited
Curry-Howard
correspondence
The Curry-Howard correspondence is a correspondence
Martin-Löf’s type
between propositions and types, and proofs and programs. theory
17
Curry-Howard correspondence (1)
Type systems:
revisited
Curry-Howard
correspondence
The Curry-Howard correspondence is a correspondence
Martin-Löf’s type
between propositions and types, and proofs and programs. theory
17
Curry-Howard correspondence (1)
Type systems:
revisited
Curry-Howard
correspondence
The Curry-Howard correspondence is a correspondence
Martin-Löf’s type
between propositions and types, and proofs and programs. theory
17
Curry-Howard correspondence (2) (exercise)
Type systems:
revisited
Curry-Howard
Given: correspondence
Martin-Löf’s type
Γ ,α`β theory
Γ1 ,α,Γ2 `α (axiom) Γ `α→β (→ introduction)
Γ `α→β Γ `α
Γ `β (→ elimination)
18
Curry-Howard correspondence (2) (exercise)
Type systems:
revisited
Curry-Howard
Given: correspondence
Martin-Löf’s type
Γ ,α`β theory
Γ1 ,α,Γ2 `α (axiom) Γ `α→β (→ introduction)
Γ `α→β Γ `α
Γ `β (→ elimination)
18
Outline
Type systems:
revisited
Curry-Howard
Type systems: revisited correspondence
Martin-Löf’s type
theory
Curry-Howard correspondence
19
Type theory: a programming language
Type systems:
revisited
I Per Martin-Löf developed a formalism for constructive
Curry-Howard
mathematics, the intuitionistic theory of types. correspondence
Martin-Löf’s type
theory
20
Type theory: a programming language
Type systems:
revisited
I Per Martin-Löf developed a formalism for constructive
Curry-Howard
mathematics, the intuitionistic theory of types. correspondence
Martin-Löf’s type
I By C-H, this formalism can also be used for program theory
20
Type theory: a programming language
Type systems:
revisited
I Per Martin-Löf developed a formalism for constructive
Curry-Howard
mathematics, the intuitionistic theory of types. correspondence
Martin-Löf’s type
I By C-H, this formalism can also be used for program theory
20
Type theory: a programming language
Type systems:
revisited
I Per Martin-Löf developed a formalism for constructive
Curry-Howard
mathematics, the intuitionistic theory of types. correspondence
Martin-Löf’s type
I By C-H, this formalism can also be used for program theory
20
Constructive mathematics
Type systems:
I Proofs should be constructive! revisited
• Classical logic uses rules such as “excluded middle” Curry-Howard
correspondence
(tertium non datur) and reductio ad absurdum (RAA).
Martin-Löf’s type
theory
21
Constructive mathematics
Type systems:
I Proofs should be constructive! revisited
• Classical logic uses rules such as “excluded middle” Curry-Howard
correspondence
(tertium non datur) and reductio ad absurdum (RAA).
Martin-Löf’s type
theory
I However, we’re not able to prove Γ ` α ∨ ¬α from
nothing. This would amount to having a proof, and thus
a program, of either one of these propositions.
21
Constructive mathematics
Type systems:
I Proofs should be constructive! revisited
• Classical logic uses rules such as “excluded middle” Curry-Howard
correspondence
(tertium non datur) and reductio ad absurdum (RAA).
Martin-Löf’s type
theory
I However, we’re not able to prove Γ ` α ∨ ¬α from
nothing. This would amount to having a proof, and thus
a program, of either one of these propositions.
I We would need either a proof for α or a proof for ¬α
and then construct the disjunction from that.
21
Constructive mathematics
Type systems:
I Proofs should be constructive! revisited
• Classical logic uses rules such as “excluded middle” Curry-Howard
correspondence
(tertium non datur) and reductio ad absurdum (RAA).
Martin-Löf’s type
theory
I However, we’re not able to prove Γ ` α ∨ ¬α from
nothing. This would amount to having a proof, and thus
a program, of either one of these propositions.
I We would need either a proof for α or a proof for ¬α
and then construct the disjunction from that.
I Also important, because we want total correctness, the
programming language will also need to be total.
21
Haskell and the Curry-Howard correspondence
Type systems:
revisited
Curry-Howard
correspondence
Martin-Löf’s type
theory
Question:
Why do we need totality? (Think of Haskell or fix.)
22
Formalising constructive mathematics
Type systems:
One of the main issues of formalising constructive revisited
mathematics was to fully make the mathematics explicit. Curry-Howard
correspondence
Martin-Löf’s type
theory
23
Formalising constructive mathematics
Type systems:
One of the main issues of formalising constructive revisited
mathematics was to fully make the mathematics explicit. Curry-Howard
correspondence
This is in contrast to normal natural deduction rules:
Martin-Löf’s type
theory
A
A ∨B
23
Formalising constructive mathematics
Type systems:
One of the main issues of formalising constructive revisited
mathematics was to fully make the mathematics explicit. Curry-Howard
correspondence
This is in contrast to normal natural deduction rules:
Martin-Löf’s type
theory
A
A ∨B
23
Formalising constructive mathematics
Type systems:
One of the main issues of formalising constructive revisited
mathematics was to fully make the mathematics explicit. Curry-Howard
correspondence
This is in contrast to normal natural deduction rules:
Martin-Löf’s type
theory
A
A ∨B
23
Proposition as sets
Type systems:
revisited
I In Martin-Löf’s type theory propositions are interpreted Curry-Howard
correspondence
as sets whose elements represent the proofs of the
Martin-Löf’s type
proposition. theory
24
Proposition as sets
Type systems:
revisited
I In Martin-Löf’s type theory propositions are interpreted Curry-Howard
correspondence
as sets whose elements represent the proofs of the
Martin-Löf’s type
proposition. theory
24
Proposition as sets
Type systems:
revisited
I In Martin-Löf’s type theory propositions are interpreted Curry-Howard
correspondence
as sets whose elements represent the proofs of the
Martin-Löf’s type
proposition. theory
24
Proposition as sets
Type systems:
revisited
I In Martin-Löf’s type theory propositions are interpreted Curry-Howard
correspondence
as sets whose elements represent the proofs of the
Martin-Löf’s type
proposition. theory
24
Proposition as sets
Type systems:
revisited
I In Martin-Löf’s type theory propositions are interpreted Curry-Howard
correspondence
as sets whose elements represent the proofs of the
Martin-Löf’s type
proposition. theory
24
Proposition as sets
Type systems:
revisited
I In Martin-Löf’s type theory propositions are interpreted Curry-Howard
correspondence
as sets whose elements represent the proofs of the
Martin-Löf’s type
proposition. theory
24
Proposition as sets
Type systems:
revisited
I In Martin-Löf’s type theory propositions are interpreted Curry-Howard
correspondence
as sets whose elements represent the proofs of the
Martin-Löf’s type
proposition. theory
24
Judgements
Type systems:
Four (or five) types of judgements: revisited
Curry-Howard
1. A is a set. (proposition) correspondence
Martin-Löf’s type
theory
25
Judgements
Type systems:
Four (or five) types of judgements: revisited
Curry-Howard
1. A is a set. (proposition) correspondence
Martin-Löf’s type
2. A1 and A2 are equal sets. (equal propositions) theory
25
Judgements
Type systems:
Four (or five) types of judgements: revisited
Curry-Howard
1. A is a set. (proposition) correspondence
Martin-Löf’s type
2. A1 and A2 are equal sets. (equal propositions) theory
25
Judgements
Type systems:
Four (or five) types of judgements: revisited
Curry-Howard
1. A is a set. (proposition) correspondence
Martin-Löf’s type
2. A1 and A2 are equal sets. (equal propositions) theory
25
Judgements
Type systems:
Four (or five) types of judgements: revisited
Curry-Howard
1. A is a set. (proposition) correspondence
Martin-Löf’s type
2. A1 and A2 are equal sets. (equal propositions) theory
25
Sets, constructively (1)
Type systems:
revisited
26
Sets, constructively (1)
Type systems:
revisited
26
Sets, constructively (1)
Type systems:
revisited
26
Sets, constructively (2)
Type systems:
revisited
Curry-Howard
correspondence
Characterise its members:
Martin-Löf’s type
theory
a∈N
0∈N a 0 ∈N
27
Sets, constructively (2)
Type systems:
revisited
Curry-Howard
correspondence
Characterise its members:
Martin-Löf’s type
theory
a∈N
0∈N a 0 ∈N
27
Sets, constructively (2)
Type systems:
revisited
Curry-Howard
correspondence
Characterise its members:
Martin-Löf’s type
theory
a∈N
0∈N a 0 ∈N
27
Canonical expressions
Type systems:
To be able to define equality we first need the notion of revisited
Martin-Löf’s type
theory
28
Canonical expressions
Type systems:
To be able to define equality we first need the notion of revisited
28
Canonical expressions
Type systems:
To be able to define equality we first need the notion of revisited
28
Canonical expressions
Type systems:
To be able to define equality we first need the notion of revisited
28
Canonical expressions
Type systems:
To be able to define equality we first need the notion of revisited
28
Canonical expressions
Type systems:
To be able to define equality we first need the notion of revisited
28
Definition of a set
Martin-Löf’s type
conditions two canonical elements are equal.” theory
29
Definition of a set
Martin-Löf’s type
conditions two canonical elements are equal.” theory
29
Example of a set
Type systems:
revisited
Curry-Howard
Again: correspondence
Martin-Löf’s type
a∈N theory
0∈N a 0 ∈N
30
Example of a set
Type systems:
revisited
Curry-Howard
Again: correspondence
Martin-Löf’s type
a∈N theory
0∈N a 0 ∈N
And now also:
a = b ∈N
0=0 a 0 = b 0 ∈N
30
General rules of equality
Type systems:
revisited
Curry-Howard
correspondence
Some rules for equality: Martin-Löf’s type
theory
a∈A A type
a=a∈A A =A (Reflexivity)
a=b ∈A b =c∈A A =B B =C
a=c∈A A =C (Transitivity)
31
Definitions of other judgements etc.
Type systems:
revisited
Curry-Howard
correspondence
Martin-Löf’s type
theory
Similar to the concepts of sets we need to define semantics
of judgements under assumptions, etc.
32
Definitions of other judgements etc.
Type systems:
revisited
Curry-Howard
correspondence
Martin-Löf’s type
theory
Similar to the concepts of sets we need to define semantics
of judgements under assumptions, etc.
(See Nordström(1990) or Per Martin-Löf (1984b).)
32
Martin Löf and dependent types
Type systems:
I Similar to the general rules for equality and union, revisited
33
Martin Löf and dependent types
Type systems:
I Similar to the general rules for equality and union, revisited
33
Martin Löf and dependent types
Type systems:
I Similar to the general rules for equality and union, revisited
(x ∈ A )
A type B (x) type
Π(A ,B ) type
33
Martin Löf and dependent types
Type systems:
I Similar to the general rules for equality and union, revisited
(x ∈ A )
A type B (x) type
Π(A ,B ) type
33
Agda and the Curry-Howard correspondence
Martin-Löf’s type
I Agda is total and we can easily see the correspondence theory
with Martin-Löf.
data > : Set where (True proposition)
tt : >
data ⊥ : Set where (False proposition)
34
References
35
Questions
Type systems:
revisited
Curry-Howard
correspondence
Martin-Löf’s type
theory
36