3. Abstract point-of-view on programming languages
To specify a (functional untyped) programming language we need:
‣ a syntax for programs (terms, sometimes modulo equations)
‣ a well-behaved substitution
‣ a syntax for reductions
‣ models (semantics)
Our work: a theoretical framework for specifying and reasoning about all the
above aspects of an abstract programming language.
Our paradigmatic example will be the -calculus with -reduction.λ β
5. Quick introduction on Initial Semantics
The essential steps are:
1. Establish a notion of signature (abstract description of a language)
2. To each signature associate a category of models
3. Prove that this category has an initial object
Then:
‣ the initial object is the language
‣ the initial morphisms are the semantics of this language.
6. Toy example: language of natural numbers
• and are constructors of arities 0 and 1 (signature: (0, 1)).
• Models are diagrams in of the form .
• The diagram is the initial model.
• The initial morphism
encodes the classical recursion principle.
Z S
𝖲𝖾𝗍 ( ∙
ZX
⟶ X
SX
⟶ X)
( ∙
Z
⟶ ℕ
S
⟶ ℕ)
( ∙
Z
⟶ ℕ
S
⟶ ℕ) ⟶ (∙
ZX
⟶ X
SX
⟶ X)
ℕ ::= Z : ℕ
| S : ℕ → ℕ
7. Beyond the syntax of terms
• It is well-known that Initial Semantics can describe the shape of terms of a
language.
• But we need more than just terms: substitution, reduction, …
• We use Initial Semantics to do this all at once.
• In other words: generate semantic morphisms that are well-behaved with
respect to:
- substitution
- binding constructions and free/bound variables
- equations
- reductions
9. Example: Monad of -termsλ
Monads (and modules over a monad) occur in our context as an axiomatic
theory of substitution.
Example: Monad of (untyped) -terms modulo -conversion:
‣
set of -terms with free variables in
‣ construction of variables
‣ parallel capture-avoiding
substitution
‣ properties of substitution (e.g. associativity) = monad laws
λ α
Λ(X) := { M | 𝖿𝗏(M) ⊆ X }
λ X
ηΛ : X ⟶ Λ(X)
𝖻𝗂𝗇𝖽Λ : (X → Λ(Y)) ⟶ (Λ(X) → Λ(Y))
10. A module over a monad is an endofunctor endowed with an action of
:
‣
‣
‣ module laws (compatibility laws with ).
NB: Every monad is trivially a module over itself.
M R
R
M : 𝖲𝖾𝗍 ⟶ 𝖲𝖾𝗍
𝗆𝖻𝗂𝗇𝖽 : (X → R(Y)) ⟶ (M(X) → M(Y))
R
R
Modules over a monad
11. Crucial examples of modules
Product: Pairs of terms of a monad :
‣
‣
Derived modules: Terms with bound variables ( set of cardinality )
‣
‣
R
R × R : X ↦ R(X) × R(X)
𝗆𝖻𝗂𝗇𝖽R×R : (X → R(Y)) ⟶ (R(X) × R(X) → R(Y) × R(Y))
n n n
R(n)
: X ↦ R(X + n)
𝗆𝖻𝗂𝗇𝖽R(n) : (X → R(Y)) ⟶ (R(X + n) → R(Y + n))
12. Example: -terms (again)λ
Application and abstraction are -modules morphisms (i.e., natural
transformations that are compatible with the substitution).
• Application:
• Abstraction:
Λ
𝖺𝗉𝗉X
: Λ(X) × Λ(X) ⟶ Λ(X)
𝖺𝗉𝗉X
: (M, N) ↦ MN
𝖺𝖻𝗌X : Λ(1)
(X) ⟶ Λ(X)
𝖺𝖻𝗌X : M[ ] ↦ λx . M[x]
15. Our stack of signatures
Signatures for syntactic constructions [CSL 2018]
Reduction rules [POPL 2020]
Signatures for equations [FSCD 2019]
}
Signatures
for monads
{
Reduction
signatures
16. What you can find in our paper
• An initial semantic approach to abstract programming language, in particular:
‣ A notion of reduction monad (mathematical model of programming language)
‣ A general notion of reduction signature that can specify reduction monads
‣ The associated notion of category of models
‣ A theorem that ensures (under suitable hypotheses) the existence of an initial
model
• Several examples of -calculi presented with our framework, including:
‣ several kind of rules and reduction strategies ( -red, hnf, whnf, parallel- ,…)
‣ extensions of the of -calculus (fixpoint operator, explicit substitution)
λ
βη β
λ