Upload
others
View
11
Download
0
Embed Size (px)
Citation preview
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Laboratoire de MathematiquesUniversite de Savoie UMR 5127
What is a programming language?
Tom HirschowitzBased on work with Richard Garner, Florian Hatat, and
Aurelien Pardon
Southampton, March 2010
Hirschowitz What is a programming language? 1/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Programming languages
Concerned, e.g., with:
Designing efficient languages, where
One more quickly writes shorter programs, with less bugs,hopefully not much slower.
Several possible specialisations (e.g., modularity, concurrency,synchrony).
Code correctness (e.g., model-checking, behaviouralequivalences).
Compiler correctness.
Hirschowitz What is a programming language? 2/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Programming languages
Recent advances: formally certified programs and compilers.
Each concerning one particular language.
Hope: generalisation.
Example
Sufficient conditions for a compiler to preserve a notion ofbehaviour.
What is a compiler? a notion of behaviour?
But wait . . . , what is a programming language?
Hirschowitz What is a programming language? 3/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Plan
1 Intro
2 First-order theories
3 Higher-order theories
4 2-signatures
5 Examples
6 Topology
Hirschowitz What is a programming language? 4/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
The big picture
The categorical approach to algebra:
1-sorted Lawvere theories
1-sorted eq. theories Finitary monads on Seta
a '
Hirschowitz What is a programming language? 5/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Equational theories
Originally, equational theories are the basis for universal algebra.
Example
The theory S for semi-groups has:
a sort t,
an operationm : t × t → t,
an equation
m(m(x , y), z) = m(x ,m(y , z)).
Hirschowitz What is a programming language? 6/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Lawvere theories
A Lawvere theory is
a category with finite products,
whose objects are all finite powers of a particular object t:
1, t, t × t, . . .
Hirschowitz What is a programming language? 7/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Equational theories and Lawvere theories
The equational theory S generates a Lawvere theory LS:
Objects: finite ordinals p, q, . . .;
Morphisms p → q: q-tuples of terms with variables in p,modulo the equations.
Composition: substitution.
Notably: morphisms p → 1 ∼= terms with variables in p.
Theorem (Lawvere)
Models of S ' finite product functors from LS.
Hirschowitz What is a programming language? 8/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Equational theories and monads
The (one-sorted) equational theory S generates a monad TS onSet:
TS(X ): terms with variables in X , modulo the equations;
µ : T2S(X )→ TS(X ): substitution;
η : X → TS(X ): variables.
Theorem
Models of S ' TS-algebras.
Hirschowitz What is a programming language? 9/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Lawvere theories and finitary monads
Restricting to the one-sorted case for simplicity:
Theorem (Lawvere, Linton)
Finitary monads on Set ' Lawvere theories.
Lawvere theories → monads:
TL(X ) =
∫ p∈ω
X p × L(p, 1),
i.e., a morphism p → 1 with variables x1, . . . , xp ∈ X (. . . ).
Hirschowitz What is a programming language? 10/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Lawvere theories and finitary monads
Restricting to the one-sorted case for simplicity:
Theorem (Lawvere, Linton)
Finitary monads on Set ' Lawvere theories.
Monads → Lawvere theories: LT determined by
LT(p, 1) = T(p).
Hirschowitz What is a programming language? 10/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
The big picture
1-sorted Lawvere theories
1-sorted eq. theories Finitary monads on Seta
a '
Hirschowitz What is a programming language? 11/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
How about binding?
Question
Can monads model binding (and in which sense)?
Hirschowitz What is a programming language? 12/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Can monads model binding?
Yes!
Example: the pure λ-calculus is a monad on Set with
Λ(X ): λ-terms with free variables in X (modulo β).
It is finitary, but not generated by any finite equationalsignature.
Reason: binding is not expressible in the language ofequational signatures.
Hirschowitz What is a programming language? 13/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Can monads model binding?
So, monads do model binding.
But outside the reach of equational theories:
1-sorted Lawvere theories
1-sorted eq. theories Finitary monads on Seta
a '
How to specify languages with binding?
Hirschowitz What is a programming language? 14/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
A solution
Fiore et al., Hirschowitz (father) et al. propose to extend theories:
Allow operations to have binding arities, e.g.:
λ : 1→ 0 @: 0× 0→ 0.
Replace Lawvere theories with a more complicated framework(Fiore et al.).
Deliberate restriction to 2nd order theories:
Reason (Fiore)
Will to explain the λ-calculus by something strictly weaker.
Hirschowitz What is a programming language? 15/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Another solution
Accept general higher-order theories (in a minute).
Categorically: finite products + exponentials.
Cost (?): the syntactic category is much larger than justterms.Indeed it includes a form of higher-order contexts.
Benefit: simple categorical picture.
Slogan
One binder to explain them all.
Hirschowitz What is a programming language? 16/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Higher-order signatures
A higher-order signature X is given by:
a set X0 of sorts;
for all formulas A,B ∈ F(X0), a set X1(A,B) of operations,
where formulas are defined by the grammar:
A,B, . . . ∈ F(X0) ::= x | 1 | A× B | BA x ∈ X0.
Hirschowitz What is a programming language? 17/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
A ho signature
Example
One sort t.
Two operations
L : tt → t A : t × t → t.
Call this signature Λ.
Hirschowitz What is a programming language? 18/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Return of the 7th son of the λ-calculus
Consider a ho signature X .
Think of the (simply-typed) λ-terms L1(X ) with:I base types in X0,I constants x : A ` c(x) : B for all c ∈ X1(A,B),I modulo α-renaming but not βη.
Hirschowitz What is a programming language? 19/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Higher-order theories
Definition
A higher-order theory X consists of:
a higher-order signature (X0,X1),
a set X2 of equations, i.e., parallel terms
Γ ` M,N : A
in L1(X0,X1).
Hirschowitz What is a programming language? 20/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Generating a CCC
Consider a ho theory X = (X0,X1,X2).
Recall the λ-terms L1(X0,X1).
Consider the smallest congruence on L1(X0,X1) generated by:
I βη,I plus the equations in X2.
This yields a λ-calculus, and a CCC C(X ).
Theorem
C(X ) is the free CCC on X .
Hirschowitz What is a programming language? 21/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Examples: variations on λ
Recall our signature Λ: L : tt → t A : t × t → t.
Proposition
For the theory Λ with no equations:
C(Λ)(tn, t) ∼= pure λ-terms in n variables.
Proposition
For the theory Λ′ with one equation:
A(L(λx .M),N) = (λx .M)N,
C(Λ′)(tn, t) ∼= pure λ-terms in n variables, modulo β.
Hirschowitz What is a programming language? 22/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
An adjunction
We obtain a category of ho theories and a monadic adjunction:
HO th. ⊥ CCCs.
C
U
Hirschowitz What is a programming language? 23/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Updating the big picture
Restricting again to the 1-sorted case:
1-sorted closed Lawvere theories
1-sorted ho theories Finitary monads on Set?
a
We still have the generated monad
TL(X ) =
∫ p∈ω
X p × L(p, 1).
Hirschowitz What is a programming language? 24/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Updating the big picture
Restricting again to the 1-sorted case:
1-sorted closed Lawvere theories
1-sorted ho theories Finitary monads on Set?
a
How to get the closed structure from an arbitrary monad?
Or by what should we replace Set to restore the triangle?
Do not yet know.
Hirschowitz What is a programming language? 24/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Equations vs. rewrite rules
Programming languages have syntax with binding.
But dynamics, not just equations.
Equations M = N Rewrite rules M → N.
Definition
A 2-signature X consists of:
a higher-order signature (X0,X1),
a set X2 of rewrite rules, i.e., parallel terms
Γ ` M,N : A
in L1(X0,X1).
Hirschowitz What is a programming language? 25/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Rewriting with binding
A 2-signature is formally the same as a ho theory.
Before we used it to define a congruence on morphisms.
Now we use it to generate a cartesian closed 2-category(2CCC).
Thanks to a 2λ-calculus L2(X ) in the style of Hilken.
Theorem (in progress)
The 2λ-calculus yields the free 2CCC on X .
A categorical semantics for rewriting with binding.
Hirschowitz What is a programming language? 26/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
The pure λ-calculus
Sort t.
Operations
L : tt → t A : t × t → t.
RewriteA(L(λx .M),N)→ (λx .M)N.
Reductions
Generated 2CCC ≈ Levy category of reductions.
I.e., reductions up to permutation of independent rewrites.
Hirschowitz What is a programming language? 27/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
A non example: π
Sorts p and n (processes and names).
Operations
s : n × n × p → p g : n × pn → p z : 1→ p
ν : pn → p | : p × p → p
Rewrites
x : pn, y : p ` (νx) | y ↔ νλa.(x(a) | y) : p . . .
x : pn, y : p, a, b : n ` s(a, b, y) | g(a, x)→ y | x(b) : p
Non-example: illegitimate non-identity loops.
Would require 2-theories, i.e., equations between rewrites.
Hirschowitz What is a programming language? 28/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Module systems: core language
Fix a set a, b, . . . ∈ L of labels.
M ::= [E ] | . . . Module expressionsE ::= M.a | . . . Core expressions
Common practice: abstract over part of the core language.
Never properly formalised.
Assume a 2-signature with sorts t and m and operations
val : t → m πa : m→ t.
No need to specify everything.
Hirschowitz What is a programming language? 29/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Module systems: structures
M ::= [E ] | {D} | . . . Module expressionsE ::= M.a | . . . Core expressionsD ::= ∅ | a . x = M; D Structure
Sorts t,m, d .
Operations as above plus:
consa : t × d t → d nil : 1→ d {·} : d → t.
Then interpret {a . x = M; b . y = N} as
{consa(M, λx .consb(N, λy .nil))}
Hirschowitz What is a programming language? 30/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
From synthesis to analysis
Systematic definition of rewriting systems with bindingI by a universal property,I defining a category of models at the same time.
Future work: extension to 2-theories to deal with structuralcongruence.
Beyond definition, analysis, cf. introduction
Code and compiler correctness.
Behavioural equivalences.
Hirschowitz What is a programming language? 31/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Towards analysis
Thesis
General understanding of such analyses will emerge from makingthe topology of programming languages explicit.
Hirschowitz What is a programming language? 32/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Topology for syntax
Main property of the free CCC over a signature
Morphisms p → 1 ∼= terms with variables in p.
There are other structures satisfying this!
Hirschowitz What is a programming language? 33/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Symmetric monoidal closed categories
First example: the free SMCC.
Girard, Trimble, then Hughes have shown its topologicalnature.
Instead of finite products and exponentials: ⊗, (, I .
Hirschowitz What is a programming language? 34/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Symmetric monoidal closed categories
Need two sorts t and v , with operations:
L : (v ( t)→ t A : t ⊗ t → t
D : v → t C : v → v ⊗ v W : v → I .
Hirschowitz What is a programming language? 35/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Symmetric monoidal closed categories
First example, λx .(x x):
t
L
C
D D
A
Hirschowitz What is a programming language? 36/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Symmetric monoidal closed categories
Example morphisms:
(v( t )⊗ t
t
L
A
t ⊗(v( t )
t
L
A
Both are λx .(�1 �2), but with x constrained differently.
Hirschowitz What is a programming language? 37/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Results
As mentioned: translation 2nd-order theory SMC theory.
The sort t becomes two:I t for terms (linear),I v for variables (non-linear).
Translate an arity 2, 3→ 1 into
(v⊗2 ( t)⊗ (v⊗3 ( t)→ t.
Terms with p variables ∼= morphisms v⊗p → t.
Finer than ho theories: can handle linearity!
Leads to a principled approach to Milner’s bigraphs (Concur’09).
Hirschowitz What is a programming language? 38/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Conclusions on SMCCs
SMCCs bring topological reasoning to the world of syntaxwith binding.
Finer than ho theories.
But: there are some features of SMCCs we do not understandor use in terms of binding.
Hirschowitz What is a programming language? 39/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Example: Trimble rewiring
((t( I )( I )( I
((t( I )( I )( I
6=
((t( I )( I )( I
((t( I )( I )( I
Different in the free SMCC.
Equal in the free CCC.
Hirschowitz What is a programming language? 40/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
How about reversing the process?
The Leinster-Weber theory of nerves extracts the algebraicstructure from a specification in terms of “shapes”.
Possible future work: use shapes and rely on Leinster-Weberto produce an algebraic structure?
Hirschowitz What is a programming language? 41/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Topology for dynamics
Using SMCCs brings topological reasoning to syntax withbinding.
No proposal yet to extend this to the dynamics.
Hirschowitz What is a programming language? 42/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
A sketch
Principle
A language consists of:
an intrinsic topology;
a rule of the game.
Programs come only later, as a syntax for constructingstrategies.
Similar to: labelled transition system with topology onvertices.
Hirschowitz What is a programming language? 43/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Example: positions
Directed (open) forests.
x
t
y z
(I name vertices to keep track of them in the next slide.)
Hirschowitz What is a programming language? 44/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Example: move
Imagine that in
x
y z
x plays y z ,
both y and z play δ = λx .x x .
x splits its edge from y :I on one x plays the argument (by copycat-ing z),I on the other y plays the result.
Hirschowitz What is a programming language? 45/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Example: move
Imagine that in
x
y z
x x
y z
x plays y z ,
both y and z play δ = λx .x x .
x splits its edge from y :I on one x plays the argument (by copycat-ing z),I on the other y plays the result.
Hirschowitz What is a programming language? 45/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
The presheaves of strategies
Positions.
Morphisms 1: embeddings. Category H.
Restriction of a strategy to a subspace.
Strategies form a presheaf Hop → Set.
Local strategies for a sheaf.
Amalgamation in the sheaf encompasses parallel composition.
Hirschowitz What is a programming language? 46/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
The presheaves of strategies
Positions.
Morphisms 2: plays. Category P.
Restriction of a strategy along a move:m∗(σ) = {p | mp ∈ σ}.Strategies form a functor P→ Set.
Taking as set of cones∐
positions X
moves to X ,
Strategies form a model for the corresponding sketch.
Hirschowitz What is a programming language? 47/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Hiding
Hide a connected subposition
•
•
into •
Category C.
Strategies form a functor C→ Set.
This encompasses game semantic hiding.
Hirschowitz What is a programming language? 48/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
In progress
A full abstraction result for a calculus of continuations.
Hirschowitz What is a programming language? 49/50
Intro First-order theories Higher-order theories 2-signatures Examples Topology
Conclusions
Question: which universe of discourse for reasoning onprogramming languages?
An algebraic approach using cartesian closed (2-)categories.
More topological attempts under investigation.
Thanks for your attention.
Hirschowitz What is a programming language? 50/50