Inductive definition

  • type, has type, is of type

  • judgement

  • inductive definition, induction

  • inference rules (axioms)

  • derivation

  • typing rules

Static Semantics

Foundations of Programming Languages: Static Semantics by Jan Hoffmann at OPLSS 2018 https://www.youtube.com/watch?v=r6r8vxSKQqY&list=PL0DsGHMPLUWW2LH62Z8W57vYz-BhqY4_r&index=2

  • Judgement: the expr e has type Ο„, denoted by |- e : Ο„

  • We define what judgements mean by induction (by inductive definitions)

For example, to define binary trees, we say that

  • Leaf is a tree (base case), |- Leaf : tree

  • if n is a number and t₁ and tβ‚‚ are trees, then Node n t₁ tβ‚‚ is a tree, n : β„•, t₁ : tree, tβ‚‚ : tree |- Node n t₁ tβ‚‚ : tree

  • This inductive definition defines a judgement that t is a tree, t : tree

  • Actually, (I've used a turnstile above, but) the turnstile signifies derivations obtaind from the rules of inference (axioms), which is not the same.

  • turnstile signifies derivations: you can derive this judgment from these rules

  • Inductive definition is saying that something is a set and that the set is closed under the application of some inference rules (axioms). So, a binary tree is defined as being closed under the 2 inference rules, which also means that binary trees are all things that could be derived from them.

  • In PLT, these rules are called inference rules

  • Inference rules are for inductively defining judgements

  • Their general form is premises on top and conclusions under the line

  • these two rules below are inference rules (axioms)

Rules for binary trees:

                     n : β„•   t₁ : tree   tβ‚‚ : tree
----------- (t1)     ----------------------------- (t2)
Leaf : tree                Node n t₁ tβ‚‚ : tree


Rules for natural numbers:

                  n : β„•
----- (n1)      --------- (n2)
0 : β„•           S(n) : β„•
  • Derivations (use turnstile) are used to prove a claim

  • for example, to prove that Node S(0) Leaf Leaf is a tree, you would use the rules of inference to derive this judgement

----------- #n1
   0 : β„•
----------- #n2  ----------- (#t1)  ----------- (#t1)
S(0) : β„•         Leaf : tree       Leaf : tree
----------------------------------------------- (#t2)
            Node S(0) Leaf Leaf

Typing rules

Typing rules are also given by the set of inference rules

----------------- (1)    ------------------- (2)    ---------------- (3)
Ξ“ |- num(n) : num        Ξ“ |- bool(n) : bool        Ξ“, x: Ο„ |- x : Ο„


----------------------- (4)
Ξ“ |- let (e₁; x.eβ‚‚) : Ο„

(1) and (2) The first two rules above just state that numbers have type num, and that Booleans have type bool. They state the evident type that literals of that type (should) have.

(3) This rule about variables is more complex since the type of a variable depends on the context. This context that tracks the types of variables is the typing context or environment, and it is commonly denoted by the Greek capital letter Ξ“.

(3) The line Ξ“, x: Ο„ |- x : Ο„ states that the context Ξ“ extended with the var x of type Ο„ (since we have recorded in the env that var x has type Ο„), means that (indeed) var x has type Ο„. It could be also said: if the context is extended with the fact that x has type Ο„, then var x has type Ο„ indeed. This means that after type-checking the code, we found that var x must have type Ο„, so we have record this fact in the typing env Ξ“; on the subsequent lookups for type of x, we'll find that it has type Ο„ (in the context Ξ“).

The typing context (typing environment) maps variables (var names) to types.

Ξ“ |- e : Ο„

The typing context is denoted by Ξ“ and it is a mapping, meaning that every expression (e) can only have a single type (Ο„).

(4) In the typing rule for let-expr, let (e₁ x eβ‚‚) == let x = e₁ in eβ‚‚

Last updated