Types and Programming Languages | The Simply Typed Lambda Calculus
static semantics: grammar and typing rules of the language
dynamic semantics: evaluation rules
The structure of the rules that we will see: each statement, whether a premise or a conclusion, typically involves a context, a term and a classification.
For example, here is the rule . Both the premises and the conclusion take the form , which we can read "In the context , has type ."
The name "simply typed lambda calculus" is rather unwieldy, so we’ll use the traditional and shorter name
For uniformity we will present both the grammar of the language and the type rules as inference rules.
The elements of the lambda calculi described here are divided into three "sorts":
- terms
- types, We write to say that the term has the type .
- kinds, which you can think of as the types of type expressions. We write to say that the type expression has the kind .
Kinding rules in
In , there is a single kind, called .
There are two kinding rules, which describe how to form types:
The rule introduces a base type of kind . Base types correspond to primitive types available in most programming languages.
The gives us a way of forming function types from types and .
For example, the type can be derived as follows:
Environment rules in
Environments associate variables with their classifiers — i.e.
- term variables with types
- and type variables with kinds.
In there are two rules for forming environments:
Typing rules in
The tvar rule shows how to type open terms (i.e. terms with free variables).
The introduction rule shows how to form a term of type
The elimination rule shows how to apply terms of function type.
The and form the first introduction-elimination pair.
Extensions
Adding products
We introduce a new type: product type
Kinding rules for
There is a new way of forming types, so we need a new kinding rule.
Typing rules for
There are three new typing rules:
The rule shows how to build pairs: a pair of type is built from terms and of types and .
The and rules show how to deconstruct pairs.
Adding sums
We next extend with sum types, which correspond to a simple version of variants.
Kinding rules for
There is a new way of forming types, so we need a new kinding rule.
Typing rules for
There are three new typing rules:
The and rules show how to build values of sum type by injecting with or
In order to maintain the property that each term has a unique type we also require a type argument to and
The rule shows how to deconstruct sums.
In the lambda-calculus everything is a function: the arguments accepted by functions are themselves functions and the result returned by a function is another function
When discussing the syntax of programming languages, it is useful to distinguish two levels of structure.
- The concrete syntax of the language refers to the string of characters that programmers directly read and write.
- The abstract syntax is a much simpler internal representation of programs as labeled trees (called abstract syntax trees).
Definition: An occurrence of the variable is said to be bound when it occurs in the body of an abstraction . Definition: An occurrence of is free if it appears in a position where it is not bound by an enclosing abstraction on .
Definition: A term with no free variables is said to be closed; closed terms are also called combinators
Operational Semantics
redex... / beta-reduction...
Evaluation Strategies:
- full beta-reduction
- normal order strategy, the left most outer most
- call by name strategy
Recursion
Definition: Terms with no normal form are said to diverge.
- e.g.,
TODO: p61