Modèles des langages de programmation Domaines, catégories, jeux Programme de cette seconde séance: Modèle ensembliste du lambda-calcul ; Catégories cartésiennes fermées 1
Synopsis 1 — the simply-typed λ -calculus, 2 — the set-theoretic model of the λ -calculus, 3 — categories and functors 4 — cartesian categories 5 — cartesian closed categories 6 — interprétation of the simply-typed λ -calculus in a ccc 2
The simply-typed λ -calculus 3
The pure λ -calculus Terms M x M N ł x . M :: = | | The β -reduction: ( λ x . M ) N −→ M [ x : = N ] The η -expansion: M λ x . ( M x ) −→ Remark: every term is considered up to renaming ≡ α of the bound variables, typically: λ x .λ y . x λ z .λ y . z ≡ α 4
The simply-typed λ -calculus The simple types A , B are constructed by the grammar: A , B :: = α | A ⇒ B . A typing context Γ is a finite sequence Γ = ( x 1 : A 1 , ..., x n : A n ) where each x i is a variable and each A i is a simple type. A sequent is a triple x 1 : A 1 , ..., x n : A n ⊢ P : B where x 1 : A 1 , ..., x n : A n is a typing context, P is a λ -term and B is a simple type. 5
The simply-typed λ -calculus Variable x : A ⊢ x : A Γ , x : A ⊢ P : B Abstraction Γ ⊢ λ x . P : A ⇒ B Γ ⊢ P : A ⇒ B ∆ ⊢ Q : A Application Γ , ∆ ⊢ PQ : B Γ ⊢ P : B Weakening Γ , x : A ⊢ P : B Γ , x : A , y : A ⊢ P : B Contraction Γ , z : A ⊢ P [ x , y ← z ] : B Γ , x : A , y : B , ∆ ⊢ P : C Exchange Γ , y : B , x : A , ∆ ⊢ P : C 6
Subject reduction A λ -term P is simply typed when there exists a sequent ⊢ P : A Γ which may be obtained by a derivation tree. One establishes that the set of simply typed λ -terms is closed under β -réduction: Subject Reduction: If Γ ⊢ P : A and P −→ β Q , then Γ ⊢ Q : A . 7
The set-theoretic interpretation of the λ -calculus 8
Interprétation ensembliste To each atomic type α is associated a set X α Then, one extends the interpretation to every type: ] = Set ([ [ A ] ] [ [ [ α ] ] = X α [ [ A ⇒ B ] ] = [ [ B ] [ A ] ] , [ [ B ] ]) A sequent x 1 : A 1 , ..., x n : A n ⊢ M : B is interpreted as a function [ A 1 ] [ A n ] [ B ] [ ] × · · · × [ ] −→ [ ] 9
Soundness theorem Theorem. The interpretation provides an invariant of λ -terms modulo β and η . if Γ ⊢ ( λ x . M ) : A ⇒ B and ∆ ⊢ N : A , then ⊲ [ [ Γ , ∆ ⊢ ( λ x . M ) N : B ] ] [ [ Γ , ∆ ⊢ M [ x : = N ] : B ] ] = if Γ ⊢ M : A ⇒ B then ⊲ [ [ Γ ⊢ ( λ x . Mx ) : A ⇒ B ] ] = [ [ Γ ⊢ M : A ⇒ B ] ] 10
Categories and functors 11
Categories A category is given by C a class of objects [0] a set Hom ( A , B ) of morphisms [1] f : A −→ B for every pair of objects ( A , B ) a composition law ◦ : Hom ( B , C ) × Hom ( A , B ) −→ Hom ( A , C ) [2] an identity morphism [2] id A : A −→ A for every object A , 12
Categories satisfying the following properties: the composition law ◦ is associative: [3] ∀ f ∈ Hom ( A , B ) ∀ g ∈ Hom ( B , C ) f ◦ ( g ◦ h ) = ( f ◦ g ) ◦ h ∀ h ∈ Hom ( C , D ) the morphisms id are neutral elements [3] ∀ f ∈ Hom ( A , B ) f ◦ id A = f = id B ◦ f 13
Examples 1. the category Set of sets and functions 2. the category Ord of partial orders and monotone functions 3. the category Dom of domains and continuous functions 4. the category Coh of coherence spaces and linear maps 5. every partial order 6. every monoid 14
Opposite category The opposite of a category C is the category noted C op whose morphisms f : A −→ B are defined as the morphisms f : B −→ A of the original category C . 15
Product category The product A × B of two categories A B is the category whose objects are the pairs ( A , B ) of objects of A and B , ⊲ whose morphisms ⊲ ( A ′ , B ′ ) ( A , B ) −→ are the pairs of morphisms f : A −→ A ′ g : B −→ B ′ 16
Product category with composition and identities defined as expected: id ( A , B ) � ( A , B ) ( id A , id B ) � ( A , B ) ( A , B ) = ( A , B ) ( f , g ) � ( A ′ , B ′ ) ( f ′ , g ′ ) � ( A ′′ , B ′′ ) ( A , B ) ( f ′ ◦ f , g ′ ◦ g ) � ( A ′′ , B ′′ ) ( A , B ) = 17
Functors A functor between categories F : C −→ D is defined as the following data: an object FA of D for every object A of C , [0] a function [1] F A , B : Hom C ( A , B ) −→ Hom D ( FA , FB ) for every pair of objects ( A , B ) of the category C . 18
Functors One requires moreover that F preserves composition [2] FA Ff � FB Fg � FC FA F ( g ◦ f ) � FC = that F preserves the identities [2] Fid A id FA � FA � FA FA FA = 19
Illustration [ orders ] Every ordered set ( X , ≤ ) defines a category [ X , ≤ ] whose objects are the elements of X ⊲ whose hom-sets are defined as ⊲ � if x ≤ y {∗} Hom ( x , y ) = otherwise ∅ In this category, there exists at most one map between two objects 20
Illustration [ orders ] Exercise: given two ordered sets ( X , ≤ ) ( Y , ≤ ) a functor F : [ X , ≤ ] −→ [ Y , ≤ ] is the same thing as a monotonic function F : ( X , ≤ ) −→ ( Y , ≤ ) between the underlying ordered sets. 21
Illustration [ monoids ] A monoid ( M , · , e ) is a set M equipped with a binary operation M × M M · : −→ and a neutral element e : {∗} −→ M satisfying the two properties below: Associativity law ∀ x , y , z ∈ M , ( x · y ) · z = x · ( y · z ) Unit law ∀ x ∈ M , x · e = x = e · x . 22
Illustration [ monoids ] Key observation: there is a one-to-one relationship ( M , · , e ) �→ Σ ( M , · , e ) between monoids ⊲ categories with one object ∗ ⊲ obtained by defining Σ ( M , · , e ) as the category with unique hom-set Σ ( M , · , e ) ( ∗ , ∗ ) M = and composition law and unit defined as g ◦ f g · f id ∗ = e = 23
Illustration [ monoids ] Key observation: given two monoids ( M , · , e ) ( N , • , u ) a functor F : Σ ( M , · , e ) −→ Σ ( N , • , u ) is the same thing as a homomorphism f : ( M , · , e ) −→ ( N , • , u ) between the underlying monoids. Recall that a homomorphism is a function f such that ∀ x , y ∈ M , f ( x · y ) = f ( x ) • f ( y ) f ( e ) = u 24
Transformations A transformation · F −→ G θ : between two functors F , G : A −→ B is a family of morphisms ( θ A : FA −→ GA ) A ∈ Obj ( A ) of the category B indexed by the objects of the category A . 25
� � Natural transformations A transformation : F ⇒ G : A −→ B θ is natural when the diagram θ A � GA FA Ff G f θ B � GB FB commutes for every morphism f : A −→ B . 26
Isomorphism In a category C , a morphism f : A −→ B is called an isomorphism when there exists a morphism g : B −→ A satisfying et g ◦ f = id A f ◦ g = id B . Exercise. Show that g ◦ f : A −→ C is an isomorphism when f : A −→ B and g : B −→ C are isomorphisms. Exercise. Show that every functor F : C −→ D transports an isomor- phism of C into an isomorphism of D . 27
� � Bifunctors A bifunctor F from C and D to E is given by: a functor F ( A , − ) : D −→ E ⊲ for every object A of the category C a functor F ( − , B ) : C −→ E ⊲ for every object B of the category D such that the diagram F ( A , B ) F ( A , g ) � F ( A , B ′ ) F ( f , B ′ ) F ( f , B ) F ( A ′ , B ) F ( A ′ , g ) � F ( A ′ , B ′ ) commutes for all morphisms f : A −→ A ′ in C and g : B −→ B ′ in D . 28
Cartesian categories 29
� � � � � � � Products The product of two objects A and B in a category C is an object A × B equipped with two morphisms π 1 : A × B −→ A π 2 : A × B −→ B such that for every diagram f A π 1 X A × B π 2 � B g there exists a unique morphism h : X −→ A × B making the diagram f A π 1 X A × B h π 2 � B g commute. 30
Illustrations 1. The cartesian product in the category Set , 2. The lub a ∧ b of two elements a and b in an ordered set ( X , � ) , 3. The cartesian product in the category Dom , 31
Terminal object An object 1 is terminal in a category C when Hom ( A , 1 ) is a singleton for all objects A . One may consider 1 as the nullary product in C . Example 1. the singleton {∗} in the categories Set and Dom , Example 2. the maximum of an ordered set ( X , � ) 32
Cartesian category A cartesian category is a category C equipped with a product A × B for all pairs A , B of objects, and of a terminal object 1 33
� � � � � � � � Cartesian categories In every cartesian category, one finds weakening maps ǫ A : A −→ 1 , ⊲ diagonal maps obtained as δ A : A −→ A × A ⊲ id A A π 1 A A × A δ A π 2 � A id A symmetry maps obtained as γ A , B : A × B −→ B × A ⊲ π 2 B π 1 γ A , B A × B B × A π 2 � A π 1 Exercise: Show that ( − × − ) defines a bifunctor C × C −→ C . 34
Cartesian closed categories First definition 35
Recommend
More recommend