Lecture 6: Encoding of -calculus, System T & System F
Sytem F:
OCamL:
type d =
Lam of d -> d
(* Or with GADT: *)
Lam: (d -> d) -> d
fun
- application (no symbol)
Lam
match
Coq:
Inductive D :=
Lam: (D -> D) -> D
fun
- application (no symbol)
Lam
match
Find a term such that, for :
We will write the
The thing is:
Untyped
-calculus = Simply-typed -calculus + Coercion
We already have
We will use the match
of Coq (Coq = the meta-language):
app := fun x:D =>
fun y:D =>
match x with
| Lam f => f y
so that app (Lam f) y = f y
Now:
δ := Lam (fun x => app x x)
Ω := app δ δ
δ' := Lam (fun f => Lam (fun x => app f (app x x)))
Y := Lam (fun f => app (app δ' f) (app δ' f))
In the definition of
Inductive tree (A: Type) :=
Node: A -> (nat -> tree A) -> tree A
Leaf: A -> tree A
We can have element which haven’t a bounded depth.
Other example:
Inductive I :=
C : ((I -> nat) -> nat) -> I
⟶ The first I
is in a positive, but not strictly positive, position.
Postive/Negative positions
occurs strictly positively in- if
occurs positively in , then occurs negatively in - if
occurs negatively in , then occurs positively in - if
occurs stricly positively in then it occurs positively in
NB:
- Constructor:
-
Destructor:
match t with (x, y) => x (* pattern *) end
-
has an
rule on the side of thematch
destructor:where
is an evaluation context (a term with a hole)
- Constructor:
⟶ definition by co-pattern - Destructor:
-
has an
rule on the side of thematch
constructor:
match (t, u) with
(x, y) => v
end.
⟶ v[t/x][u/y]
cf. “Linear intuitionistic logic” by Nick Benton
Inductive L (A: Type): Type :=
Var : A -> LA
App : LA -> LA -> LA
Lam : L (option A) -> LA (* recursively non uniform parameter of inductive type *)
where
Inductive option (A: Type): Type :=
None : option A
Some : A -> option A
and
Inductive False := .
Show that simply-typed -terms can be encoded in the type L False
and encode and
Var : False -> L False
App : L False -> L False -> L False
Lam : L (option False) -> L False
Var
Another interesting “high-tech” type:
Inductive tree (A: Type) :=
Node : tree (tree A) -> tree A
Leaf : A -> tree A
System T and System F
- System T:
-
is the language if terms canonically associated to
- System F:
-
is the language if terms canonically associated to
- Types of system F:
-
it’s the ones of simply-typed
-calculus + second order quantification: - Terms of system F:
-
Typing rules:
NB: System F encompasses System T, and is even much more powerful.
Church encoding of natural numbers
NB: Kleene found the expression of the predecessor at the dentist’s.
Problem: the predecessor is computed in linear time, which is annoying: we would like to have it in constant time. That’s part of the reason why inductive types became so successful, in comparison.
Curryfication
Right Kan extension (
Left Kan extension (
Leave a comment