Algebraic models of simple type theories: a polynomial approach
aa r X i v : . [ c s . L O ] J un Algebraic models of simple type theories
A polynomial approach
Nathanael Arkor
Department of Computer Science and TechnologyUniversity of Cambridge
Marcelo Fiore
Department of Computer Science and TechnologyUniversity of Cambridge
Abstract
We develop algebraic models of simple type theories, layingout a framework that extends universal algebra to incorpo-rate both algebraic sorting and variable binding. Examplesof simple type theories include the unityped and simply-typed λ -calculi, the computational λ -calculus, and predicatelogic.Simple type theories are given models in presheaf cate-gories, with structure specified by algebras of polynomialendofunctors that correspond to natural deduction rules. Ini-tial models, which we construct, abstractly describe the syn-tax of simple type theories. Taking substitution structureinto consideration, we further provide sound and completesemantics in structured cartesian multicategories. This de-velopment generalises Lambek’s correspondence betweenthe simply-typed λ -calculus and cartesian-closed categories,to arbitrary simple type theories. Universal algebra is a framework for describing a class ofmathematical structures: precisely those equipped withmonosorted algebraic operations satisfying equationallaws. Though such structures are prevalent, there arenevertheless many structures of interest in computerscience that do not fit into this framework. In particular,notions of type theory, despite being presented in analgebraic style, cannot be expressed as universal algebraicstructures. Herein, we follow the tradition of algebraic typetheory [10, 12] in describing type theories as the extensionof universal algebra to a richer setting, viz. that of sorting( i.e. typing) and variable binding.There are several reasons to be interested in extendinguniversal algebra in this manner. From the perspective ofprogramming language theory, this is a convenient frame-work for abstract syntax: the structure of programming lan-guages, disregarding the superficial details of concrete syn-tax. From a categorical perspective, algebraic type theoryprovides a precise correspondence between syntactic andsemantic structure: the rules of a type theory give a conve-niently manipulable internal language for reasoning abouta categorical structure, which, in turn, models the theory.
This is a preprint of https://doi.org/10.1145/3373718.3394771 , published in
Proceedings of the 35th Annual ACM/IEEE Symposium on Logic in ComputerScience (LICS ’20) . The classical result due to Lambek [23], that the simply-typed λ -calculus is an internal language for cartesian-closedcategories, is a representative example of such a correspon-dence.In this paper, we consider the syntax and semantics of simple type theories : algebras with sorted bindingoperations, whose type structure itself is (nonbinding)algebraic. Simple type theories encompass many familiarexamples beyond algebraic theories, including theunityped and simply-typed λ -calculi, the computational λ -calculus [26], and predicate logic. Similar extensions touniversal algebra have been explored in the past[5, 15, 17, 18], but previous approaches have provendifficult to extend to the dependently-sorted setting that isnecessary to describe more sophisticated type theoriessuch as Martin-Löf Type Theory [25]. We describe a newapproach, combining the theories of abstract syntax [18]and polynomial functors [20], which we feel is anappropriate setting to consider dependently-sortedextensions. Philosophy
Type theories are typically presented by systems of natu-ral deduction rules describing the inductive structure of thetheory. Models of the type theory will therefore have cor-responding structure. The observation that motivates ourapproach may be summarised by the following thesis.
Natural deduction rules are syntax for polynomials.
In this paper we give an exposition of this idea, describinga polynomial approach to the semantics of simple type the-ories. Concretely, we will show how the natural deductionrules presenting the algebraic structure of a simple type the-ory, which are described precisely by a class of arities, in-duce polynomial functors in presheaf categories whose alge-bras are exactly models of the type theory. In particular, theinitial algebras are the syntactic models, whose terms areinductively generated from the rules. This provides a corre-spondence between type theoretic and categorical structure.To build intuition for the general setting, we will frame theclassical example of the simply-typed λ -calculus in this newperspective.The relationship between polynomials and the algebraicstructure of type theories was first proposed by Fiore [13],in the context of generalised polynomial functors between athanael Arkor and Marcelo Fiore presheaf categories. Though our approach is similarlymotivated, the setting is different: we consider traditionalpolynomial functors between slice categories. This is asetting that has been more widely studied [1, 20] and onewe suggest also extends more readily to modellingdependent type theories: Awodey and Newstead [3, 4, 28],for instance, have also considered a relationship betweenpolynomial pseudomonads and natural models of typetheory [3]. Their setting, however, is entirely semantic,and one in which the significance of polynomials in thestructure of natural deduction rules is not apparent.In this framework, we consider two classes of models:models of simply typed syntax (Section 5), and models of simple type theories (Section 8). Both classes of modelshave algebraic type structure and multisorted binding( i.e. second-order) algebraic term structure, but simple typetheories extend syntax in two ways: while syntax hererefers to those terms solely built inductively from naturaldeduction rules, type theories additionally have anassociated notion of (capture-avoiding) substitution: avariable in a term may be replaced by a term of the sametype, taking care not to bind any free variables. Typically, asyntax gives rise to a type theory, as one can add asubstitution operation that commutes with the operatorsof the syntax. For this reason, many models of universalalgebra do not draw a distinction between syntax and typetheory: for instance, Lawvere theories [24] have a built-innotion of substitution, given by composition of morphisms.However, it is useful to consider these two notionsseparately: substitution gives rise to rich structure that onecan only observe by treating it explicitly, for example thesubstitution lemma (Theorem 6.3) that is ubiquitous intreatments of type theory.We also consider only type theories (and not syntax) tobe equational, as modelling equations involves identifyingterms that are syntactically distinct. Contributions
The main contributions of this paper are the following.1. A new perspective on natural deduction rules, pre-senting natural deduction rules for formation, intro-duction and elimination, as the syntax for polynomi-als in presheaf categories.2. A general definition of models of simply typed syntaxand simple type theories.3. Initiality theorems, giving a construction of the initialmodels of simply typed syntax and simple type theo-ries.4. A correspondence between models of simple type the-ories and classifying multicategories, generalising theclassical Lambek correspondence between the simply-typed λ -calculus and cartesian-closed categories. This work provides a basis for our ongoing developmentof algebraic dependent type theory. Organisation of the paper
We build up the definition of a simple type theory in parts,presenting the syntax and semantics in conjunction.Section 2 describes the monosorted nonbindingalgebraic structure of types, which is standard fromuniversal algebra. Section 3 considers variable contextsand introduces models thereof. Section 4 is the centralcontribution of the paper and explains how the multisortedbinding algebraic structure on terms may be presented bysyntax for polynomials corresponding to natural deductionrules. Section 5 defines categories of models of simplytyped syntax and gives a construction of the initial model(Theorem 5.7). Section 6 introduces substitution structureon terms and establishes a substitution lemma(Theorem 6.3). Section 7 describes equations on terms,which crucially relies on the substitution structure fromthe preceding section. Section 8 defines categories ofmodels of simple type theories, which extend syntax byhaving substitution and equational structure, and leads toa construction of the initial model (Theorem 8.4). Section 9demonstrates how models of simple type theories inducestructured cartesian multicategories, establishing ageneralised Lambek correspondence (Theorem 9.2 andCorollary 9.4).
We consider types with monosorted nonbinding algebraicstructure à la universal algebra. The type constructors ofthe simply-typed λ -calculus are examples of such algebraicstructure; consider the following formation rules. Unit - form Unit type A type B type Prod - form Prod ( A , B ) type A type B type Fun - form Fun ( A , B ) type These types may be modelled by a set S of sorts with afunction expressing the denotations of the type construc-tors. Base types are described by nullary type constructors,as in universal algebra.1 + S + S [ J Unit K , J Prod K , J Fun K ] −−−−−−−−−−−−−−−−→ S This structure is an algebra for the endofunctor on
Set map-ping S S + S + S . This is an example of a polynomialfunctor on Set . Polynomial functors are a categorification ofthe notion of polynomial functions and similarly represent“sums of products of variables”. Just as a polynomial func-tion is presented by a list of coefficients, polynomial func-tors are presented by polynomials , which are diagrams of lgebraic models of simple type theories the following shape. I s ←− A f −→ B t −→ J Such a polynomial in
Set induces a polynomial functor
Set / I → Set / J , given by the following, where B j = t − ( j ) and A b = f − ( b ) . ( X i | i ∈ I ) 7→ ( Σ b ∈ B j Π a ∈ A b X s ( a ) | j ∈ J ) This is slightly more sophisticated than the traditional sumof products: in particular, we also have a notion of reindex-ing. Clear introductions to polynomial functors are given inGambino and Kock, Weber [20, 29].Type constructors correspond generally to polynomialsin
Set . Consider the
Prod type constructor, for instance. Itinduces the following very simple polynomial.1 ← + → → (−) 7→ (−) × (−) , algebras forwhich are sets S with a function J Prod K : S → S as in-tended.Type operators ( i.e. formation rules) are described gener-ally in terms of arities. Notation 2.1.
Let M : Set → Set be the free monoid endo-functor. For any functor F : Set → Set , define F ⋆ def = M ◦ F . Definition 2.2.
We define ar k : Set → Set , for k ∈ N ,inductively. ar = Id ar k + = ar k ⋆ × ar k We call ar k ( S ) the set of S -sorted k th -order arities . Notation 2.3.
We denote by A , . . . , A n → A the S -sortedfirst-order arity (cid:0) ( A , . . . , A n ) , A (cid:1) ∈ ar ( S ) . We identifynullary arities with constants and omit the arrow ( → )when n = Notation 2.4.
We denote by n the set { , . . . , n } , for n ∈ N .In particular, 0 is the empty set.First-order arities correspond to the operators of (multi-sorted) universal algebra [5], though in this setting we aresolely concerned with monosorted operators. Specifically,our type operators are represented by {∗} -sorted first-orderarities, where ∗ is the unique kind.In general, an n -ary type operator O : ∗ , . . . , ∗ | {z } n ∈ N → ∗ corresponds to a type formation rule of the form A type · · · A n type O - form O ( A , . . . , A n ) type where A , . . . , A n are type metavariables, universally quan-tified over all types.An n -ary type operator induces a polynomial in Set ← n → → {∗} ← { A : ∗} + · · · + { A n : ∗} → { O ( A , . . . , A n ) : ∗} → {∗} An algebra for the induced polynomial functor is given ex-plicitly by a set S and a function J O K : S n → S . We col-lect the arities into a single signature , which completely de-scribes the inductive structure of the types. Definition 2.5. A type operator signature , denoted O ty , isgiven by a list of {∗} -sorted first-order arities. Notation 2.6.
To aid readability, we will use the followinginformal notation throughout. The ⊲ symbol separates thetype metavariables from a type, term or equation involvingthem. For example, the notation A , B : ∗ ⊲ Prod ( A , B ) : ∗ specifies a {∗} -sorted first-order arity ∗ , ∗ → ∗ . Example 2.7 (Formation rules for the simply-typed λ -calculus) . Let I ∈ Set be a finite set of base types. ⊲ Base i : ∗ ( i ∈ I ) ⊲ Unit : ∗ A , B : ∗ ⊲ Prod ( A , B ) : ∗ A , B : ∗ ⊲ Fun ( A , B ) : ∗ A type operator signature induces a polynomial (resp.polynomial functor), given by taking the coproduct of thepolynomials (resp. polynomial functors) induced by itselements.
Notation 2.8.
We will denote by O ty both a type operatorsignature and the polynomial functor O ty : Set → Set itinduces.The polynomial functor O ty induces a monad giving theclosure of a set of type metavariables under the operators ofthe signature. Notation 2.9.
Given a type operator signature O ty , we de-note by O ∗ ty the free O ty -algebra monad on Set .The Eilenberg–Moore category of the monad O ∗ ty is iso-morphic to the category of O ty -algebras. We permit types to be identified by means of equationallaws. For any m ∈ N , the set O ∗ ty ( m ) may be consideredsyntactically as the set of types parameterised by m typemetavariables. Each element of m acts as a placeholder,which one can substitute for a concrete type, by the athanael Arkor and Marcelo Fiore freeness of O ∗ ty ( m ) as in the following. A morphism A asbelow corresponds to a family of sorts ( A i ) ≤ i ≤ m ∈ S m . O ty ( O ∗ ty ( m )) O ty ( S ) O ∗ ty ( m ) Sm A η Ψ A J ty K ∗ J ty K O ty ( Ψ A ) (1) Definition 2.10. An O ty -type equation is given by a pair (cid:0) m ∈ N , ( L , R ) ∈ O ∗ ty ( m ) (cid:1) , representing an equationbetween types L ≡ R parameterised by m metavariables.An O ty -type equation induces a term monad identifyingthe terms in the ( L , R ) pair [16], intuitively given by quoti-enting O ∗ ty by the equation. Definition 2.11. An equational type signature , typically de-noted Σ ty , is given by a type operator signature O ty and a list E ty of O ty -type equations. Definition 2.12.
Given an equational type signature Σ ty = ( O ty , E ty ) , a Σ ty -algebra is an O ty -algebra satisfying the equa-tions of E ty . Notation 2.13.
Given an equational type signature Σ ty , wedenote by Σ ∗ ty the associated term monad on Set .The term monad associated to an equational typesignature (cid:0) O ty , [ ] (cid:1) is the free O ty -monad O ∗ ty . For any list of O ty -type equations E ty , there is a canonical quotientmonad morphism O ∗ ty ։ Σ ∗ ty . Example 2.14 (Unityped λ -calculus) . In the unityped λ -calculus there is a single type constant D : ∗ and a singletype constructor Fun : ∗ , ∗ → ∗ , where function types areidentified with the base constant: ⊲ D ≡ Fun ( D , D ) . Type theories have a notion of (variable) context , explicitlyquantifying the free variables that may appear in a term.Here, we take the contexts of simple type theories to becartesian: intuitively, lists of typed variables, admittingexchange, weakening, and contraction. Cartesian contextstructures model the structure of such contexts.
Definition 3.1.
Given an equational type signature Σ ty = ( O ty , E ty ) , a cartesian Σ ty -typed context structure for an alge-bra J ty K : Σ ∗ ty ( S ) → S consists of • a small category C , the category of contexts , with aspecified terminal object ϵ , the empty context ; • a functor h−i : S → C , embedding sorts as single-variable contexts , where S denotes the discrete cate-gory on a set S ; • for all Γ ∈ C and A ∈ S , a specified product Γ × h A i , context extension of Γ by a variable of sort A . Notation 3.2.
We write
Cart ( S ) for the free strict cartesiancategory on a set S , given concretely by the opposite of thecomma category ( F ֒ → Set ) ↓ ( S : → Set ) , where F is theskeleton of the category of finite sets and functions. Example 3.3.
Every algebraic theory [2] (that is, a carte-sian category) C is an example of a cartesian Id | C | -typedcontext structure (in fact, one closed under concatenation,rather than just extension). Definition 3.4. A homomorphism of cartesian Σ ty -typedcontext structures from ( C , S ) → ( C ′ , S ′ ) consists of • a functor H : C → C ′ ; • a Σ ∗ ty -algebra homomorphism h : S → S ′ ,such that the following diagram commutes. C × S C ′ × S ′ C × C C ′ × C ′ C C ′ Hϵ ϵ ′ × id ×h−i H × h id ×h−i ′ × Cartesian Σ ty -typed context structures and their homo-morphisms form a category. Proposition 3.5.
There is a left-adjoint free functor takingsets S to the free cartesian Σ ty -typed context structure on S ,given by Cart ( Σ ∗ ty ( S )) with h−i the canonical embedding.In particular, the free cartesian Σ ty -typed context struc-ture on ∅ is the initial object. We follow the tradition of abstract syntax, initiated inFiore, Plotkin, and Turi [18], of representing models ofterms as presheaves over categories of contexts. Inparticular, for a cartesian Σ ty -typed context structure C ,we consider presheaves T : C op → Set as sets of terms,indexed by their context. For each context Γ ∈ C op , T ( Γ ) isto be regarded as the set of terms with variables in Γ ; whilea morphism ρ : Γ → Γ ′ in C op , representing a contextrenaming, induces a mapping T ( ρ ) : T ( Γ ) → T ( Γ ′ ) betweenterms in different contexts. Notation 4.1.
We use the same symbol for a set S (resp.function h : S → S ′ ) and any constant presheaf on S (resp.any constant natural transformation on h ).The set of sorts S embeds into b C as a constant presheaf:intuitively a presheaf of types that do not depend on their lgebraic models of simple type theories context. In this light, a natural transformation τ : T → S in b C is to be regarded as an assignment of types to termsthat respects context renaming. The slice category b C / S isthus an appropriate setting for considering typed terms incontext. (Note that we work in the fibred setting, rather thanthe equivalent indexed setting of Fiore [9].) Definition 4.2. A typed term structure for a cartesian Σ ty -typed context structure ( C , S ) is an object of b C / S ,concretely • a presheaf T in b C , the terms ; • a natural transformation τ : T → S , the assignment ofa type for each term.The type of any term t ∈ T ( Γ ) is therefore given by τ Γ ( t ) ( cf. the view taken in Fiore [14] and Awodey’s natural mod-els [3]). Example 4.3.
The presheaf of variables for a cartesian Σ ty -typed context structure ( C , S ) forms a typed termstructure ν : V → S given by the following, where y denotes the Yoneda embedding. V def = Þ A ∈ S y h A i ν (h A , ρ i) def = A The presheaf of variables is so called because, for any con-text Γ , the set V ( Γ ) is to be regarded as the variables in Γ .We note that, for all presheaves X ∈ b C and A ∈ S , one has X V A (cid:27) X (− × h A i) , illustrating that exponentiation by V A isthe same as context extension [18] (in turn demonstratingthat context extension is polynomial). Proposition 4.4.
For all n ∈ N , the morphism ν n : V n → S n is representable.Any presheaf of terms may be restricted to just those witha specified type, by taking pullbacks, as in the following ex-ample. Example 4.5.
Given a typed term structure τ : T → S anda sort A ∈ S , we denote by T A the presheaf consisting ofterms in T whose type is A , given by the fibre: T A T S τι A A y It induces a typed term structure given by the composite T A → A −→ S . λ -calculus Terms have two additional forms of structure that is notfound in simple types: multisorting and binding. We walkthrough the illustrative algebraic term structure of thesimply-typed λ -calculus to give intuition before providingthe general construction in Section 4.3. First, we will identify the structure we expect our models to have, beforeseeing how this structure arises from our models beingalgebras for a polynomial functor in Section 4.2.As with the algebraic structure for types, the algebraicstructure for terms is presented by natural deduction rules(typically introduction or elimination rules), each rule cor-responding to an operator on terms. Products.
The introduction rule for
Prod is given by thefollowing. Γ ⊢ a : A Γ ⊢ b : B Prod - intro Γ ⊢ pair ( a , b ) : Prod ( A , B ) (2)Conceptually, the introduction rule allows one to take twoterms of any two types A and B and form a new term, theirpair, such that the type of the new term is the product J Prod K ( A , B ) , given by the algebraic structure of the types.A typed term structure τ : T → S therefore models Prod - intro when equipped with a morphism J pair K suchthat the following diagram commutes. T × T TS × S S ττ × τ J pair KJ Prod K The elimination rules for products are given by the follow-ing. Γ ⊢ p : Prod ( A , B ) Prod - elim Γ ⊢ proj ( p ) : A (3) Γ ⊢ p : Prod ( A , B ) Prod - elim Γ ⊢ proj ( p ) : B (4)A typed term structure τ : T → S models the first projec-tion when equipped with a morphism J proj K such that thefollowing left-hand square commutes, where T J Prod K is givenby the following right-hand square. T J Prod K TS × S S τ J proj K π T J Prod K TS × S S τι J Prod K y This condition is analogous to the one for the introductionrule, the primary difference being that it is only possible toproject from terms that have type
Prod ( A , B ) for some types A and B . The situation for Prod - elim is analogous. Units.
Compared to that for products, the algebraic struc-ture for units is almost trivial. The introduction rule for
Unit is given by the following.
Unit - intro Γ ⊢ u : Unit (5)A typed term structure τ : T → S for the Unit type shouldtherefore single out a term J u K with type τ ( J u K ) = J Unit K athanael Arkor and Marcelo Fiore (in any context). That is, we expect the following diagramto commute. 1 TS τ J Unit KJ u K λ -abstraction. Having considered sorting structure, wenow consider variable binding. The introduction rule for
Fun is given by the following. Γ , a : A ⊢ b : B Fun - intro Γ ⊢ abs (( a : A ) b ) : Fun ( A , B ) (6)The abs operator allows one to take a term in an extendedcontext and form a term in the original context. A typedterm structure τ : T → S therefore models Fun - intro whenequipped, for every context Γ and types A , B ∈ S , with amapping J abs K A , B Γ , natural in Γ , such that the following dia-gram on the left commutes. T B ( Γ × h A i) T ( Γ ) S τ Γ J abs K A , B Γ J Fun K ( A , B ) T BV A T S τ J abs K A , B J Fun K ( A , B ) Through the relationship between context extension and ex-ponentiation by representables (Example 4.3), this is equiv-alent to the above diagram on the right, for all A , B ∈ S . Fi-nally, quantifying over the types, this is further equivalentto the following formulation. Ý A , B ∈ S T BV A TS × S S τ J abs K π J Fun K The elimination rule is simpler. Γ ⊢ f : Fun ( A , B ) Γ ⊢ a : A Fun - elim Γ ⊢ app ( f , a ) : B (7)A typed term structure τ : T → S models function applica-tion when equipped with a morphism J app K such that thefollowing square commutes. Ý A , B ∈ S T J Fun K ( A , B ) × T A TS × S S π τ J app K π λ -calculus We now show how the above structure for models of thesimply-typed λ -calculus is actually algebraic structure for apolynomial functor. While, so far, we have only dealt withpolynomials in Set , we recall that the concept makes sensefor any presheaf category b C . For every morphism f : A → B in b C , there is an adjointtriple Σ f ⊣ f ∗ ⊣ Π f where Σ f is postcomposition by f and f ∗ : b C / B → b C / A is pullback along f . Every polynomial I ← A → B → J induces a polynomial functor Σ t Π f s ∗ : b C / I → b C / J .An algebra for a functor F : b C / S → b C / S is a typed termstructure τ : T → S with a morphism φ : dom ( F ( τ )) → T such that the following diagram commutes.dom ( F ( τ )) TS τF ( τ ) φ We will write F ( T ) to mean dom ( F ( τ )) when unambiguous.In particular, algebras for a polynomial functor, φ : Σ t Π f s ∗ ( τ : T → S ) → ( τ : T → S ) , are illustrated by thefollowing diagram. T s ∗ ( T ) Π f s ∗ ( T ) TS A B S fs tτ τ Π f s ∗ ( τ ) φs ∗ ( τ ) y We will sometimes depict polynomials geometrically as inthe following.
A BI J s tf
We may then unambiguously omit a component morphism,which is taken to be the identity. The composition of twopolynomials is also a polynomial [20, Proposition 1.12], de-picted graphically as in the following.
A B C DI J K
Products.
The condition for
Prod - intro (2) exactlystates that τ : T → S is an algebra for the polynomialfunctor induced by the following polynomial in b C . S [ π , π ] ←−−−−− S + S ∇ −−→ S J Prod K −−−−−→ S ( Prod - intro )The structure of this polynomial may seem opaque at first;we will attempt to provide some intuition. The polynomialdescribes a (many-in, one-out) transformation betweenterms, respecting the type structure. The middlecomponent ∇ : S + S → S represents the typemetavariables A and B : each summand in the domainrepresents the metavariables in a premiss, while thecodomain represents the metavariables in the conclusion.While some metavariables may not appear in everypremiss, each premiss is implicitly parameterised by eachtype metavariable; the codiagonal ensures that themetavariables available to each premiss (and theconclusion) are the same ( i.e. unified).The leftmost component S ← S + S : [ π , π ] describesthe types of each premiss, given the metavariables. In this lgebraic models of simple type theories case, the types are simply projections: the left-hand side to A and the right-hand side to B . The rightmost component J Prod K : S → S describes the type of the conclusion, giventhe metavariables: in this case, constructing the product of A and B .An algebra for the functor induced by this polynomialis calculated explicitly below, to demonstrate that it alignswith the structure we deduced earlier. T T × S + S × T T TS S + S S S J Prod K [ π , π ] ∇ τ [ π , π ] τ × id + id × τ τ = Π ∇ ( τ × id + id × τ ) τ J pair K y The polynomials for the projections are similarly described.For τ : T → S to be a model of the product eliminators Prod - elim (3) and Prod - elim (4), we require it to be an al-gebra for the following polynomials. S J Prod K ←−−−−− S ∇ −−→ S π −−→ S ( Prod - elim ) S J Prod K ←−−−−− S ∇ −−→ S π −−→ S ( Prod - elim )Given some examination, the structure of the polynomialsis analogous to that of the introduction rule, with the firstcomponent selecting the type of the premiss, the codiagonal(in this case trivially) unifying the premisses, and the finalcomponent selecting the type of the conclusion. Units.
For
Unit - intro (5), the polynomial inducing thestructure is similarly defined. For τ : T → S to be a modelof u , we require it to be an algebra for the following polyno-mial. S ! ←− ∇ −−→ J Unit K −−−−−→ S ( Unit - intro )One may see that, as the introduction rule for Unit has nopremisses and no type metavariables, this (trivially) fits thesame pattern as with
Prod . λ -abstraction. To describe binding structure, we needmore sophisticated polynomials. For τ : T → S to be amodel of Fun - intro (6), we require it to be an algebra forthe following polynomial. S π ←−− V × S ν × id −−−→ S J Fun K −−−−→ S ( Fun - intro )Here, the first and last components are familiar from the pre-vious examples. The form of the middle component is new:metavariables involved in context extension, and thereforein variable binding, must be fibred over the presheaf of vari-ables V . The typed term structure ν : V → S of Example 4.3forgets the information associated to a variable apart fromits type.For τ : T → S to be a model of Fun - elim (7), we requireit to be an algebra for the following polynomial. S [ J Fun K , π ] ←−−−−−−−− S + S ∇ −−→ S π −−→ S ( Fun - elim ) Polynomials are closed under taking coproducts: for atyped term structure to be a model of the entire structureof the simply-typed λ -calculus, therefore, we require it tobe an algebra for the polynomial endofunctor induced bythe coproduct of all the aforementioned polynomials. We now give syntax for a general natural deduction rule fora term operator and the construction of the polynomial itinduces. As with type operators, we have a notion of aritycorresponding to term operators.
Notation 4.6.
We denote by ( A , . . . , A k ) A , . . . , ( A n , . . . , A nk n ) A n → ( B , . . . , B k ) B the S -sorted second-order arity (Definition 2.2) (((( A ,..., A k ) , A ) ,..., (( A n ,..., A nkn ) , A n )) , (( B ,..., B k ) , B ))∈ ar ( S ) Second-order arities correspond to the operators of multi-sorted binding algebra [17]: such an arity represents an op-erator taking n arguments, the i th of which binds k i vari-ables, which is parameterised by k variables. We identifynullary arities with constants.Given an equational type signature Σ ty and m ∈ N typemetavariables, we can represent term operators by Σ ∗ ty ( m ) -sorted second-order arities. An n -ary term operator o : ( A , . . . , A k ) A , . . . , ( A n , . . . , A nk n ) A n → ( B , . . . , B k ) B (8) corresponds to a rule as in Figure 1, universally quantifiedover all contexts Γ . Definition 4.7.
We say that a term operator is parame-terised when k , Σ ty , asin (8), induces a polynomial in b C for any cartesian Σ ty -typedcontext structure, given in Figure 2. Definition 4.8. A term operator signature , denoted O tm , foran equational type signature Σ ty is given by a list of pairsof natural numbers m ∈ N and Σ ∗ ty ( m ) -sorted second-orderarities. Example 4.9 (Term operators for the simply-typed λ -calculus) . ⊲ u : Unit A , B : ∗ ⊲ abs : ( A ) B → Fun ( A , B ) A , B : ∗ ⊲ app : Fun ( A , B ) , A → BA , B : ∗ ⊲ pair : A , B → Prod ( A , B ) A , B : ∗ ⊲ proj : Prod ( A , B ) → AA , B : ∗ ⊲ proj : Prod ( A , B ) → B A term operator signature induces a polynomial (resp.polynomial functor), given by taking the coproduct of thepolynomials (resp. polynomial functors) induced by itselements. athanael Arkor and Marcelo Fiore Γ , x : A , . . . , x k : A k ⊢ t : A · · · Γ , x n : A n , . . . , x nk n : A nk n ⊢ t n : A n Γ , y : B , . . . , y k : B k ⊢ o [ y : B , . . . , y k : B k ] (cid:0) ( x : A , . . . , x k : A k ) t , . . . , ( x n : A n , . . . , x nk n : A nk n ) t n (cid:1) : B Figure 1.
Natural deduction rule for a term operator Ý ≤ i ≤ n S m S m V k × S m Ý ≤ i ≤ n V k i × S m Ý ≤ i ≤ n S k i × S m S k × S m SS Ý ≤ i ≤ n ν ki × id [ J A i K ◦ π ] ≤ i ≤ n Ý ≤ i ≤ n hh J A ij K i ≤ j ≤ ki , id i ∇ n hh J B j K i ≤ j ≤ k , id i ν k × id J B K ◦ π Figure 2.
Polynomial induced by a term operator Î ≤ i ≤ n T J A i K ( C ) ( Γ × h J A ij K ( C )i ≤ j ≤ k i ) T ( Γ × h J B j K ( C )i ≤ j ≤ k ) S τ Γ ×h J Bj K ( C )i ≤ j ≤ k J B K ( C ) J o K ♯ Γ ( C ∈ S m ) Natural in the context Γ , where h D , . . . , D ℓ i def = (· · · ( ϵ × h D i) × · · · ) × h D ℓ i . Figure 3.
Algebra structure induced by a term operator
Notation 4.10.
We will denote by O tm both a term operatorsignature and the polynomial functor it induces. Remark 4.11.
To gain intuition for the polynomial alge-braic structure, it is instructive to evaluate the polynomi-als oneself, starting with an arbitrary τ : T → S and tak-ing pullbacks, dependent products and postcomposing. Ofthese operations, pullbacks and postcomposing are straight-forward. We give the two relevant calculations for the de-pendent products explicitly. Π ∇ n ( P → Ý ≤ i ≤ n S m ) (cid:27) (cid:0) Ý A ∈ S m Î ≤ i ≤ n P h i , A i (cid:1) → S m Π ν k × id ( V k × P id × p −−−→ V k × S m ) (cid:27) (cid:0) Ý A ∈ S k , B ∈ S m P B Î ≤ i ≤ k V Ai (cid:1) → S k × S m Proposition 4.12.
In elementary terms, O tm -algebras forthe polynomial functor as in Figure 2 are equivalently givenby typed term structures τ : T → S with a natural transfor-mation J o K ♯ such that the diagram in Figure 3 commutes. Proposition 4.13.
For all term signatures, the endofunctor O tm on b C / S is finitary.Thus, O tm induces a monad [16] describing the term struc-ture, closed under the operators of the signature. Notation 4.14.
Given a term operator signature O tm , wedenote by O ∗ tm the free O tm -algebra monad on b C / S . The Eilenberg–Moore category of the monad O ∗ tm is iso-morphic to the category of O tm -algebras. We now give the definition of simply typed syntax, alongwith its models. Note that this is not yet a full notion ofsimple type theory, as we lack substitution and equations.
Definition 5.1. A simply typed syntax consists of: • a type operator signature O ty ; • a term operator signature O tm for O ty . Definition 5.2. A model for a simply typed syntax consistsof • an O ty -algebra J ty K : O ty ( S ) → S ; • a cartesian O ty -typed context structure C for S ; • an O tm -algebra J tm K : O tm ( τ : T → S ) → ( τ : T → S ) . Proposition 5.3. S -sorted simply-typed categories withfamilies [6] are equivalent to models of simply typedsyntax for an empty type and term signature, such that thecarriers of the O ty - and O tm -algebras are S and ν : V → S respectively.To discuss the relationships between different models of asimply typed syntax, and to prove that the syntactic model is lgebraic models of simple type theories Î ≤ i ≤ n T J A i K ( C ) ( Γ × h J A ij K ( C )i ≤ j ≤ k i ) T J B K ( C ) ( Γ × h J B j K ( C )i ≤ j ≤ k ) Î ≤ i ≤ n T ′ J A i K ′ ( h ( C )) ( H ( Γ ) × h J A ij K ′ ( h ( C ))i ≤ j ≤ k i ) T ′ J B K ′ ( h ( C )) ( H ( Γ ) × h J B j K ′ ( h ( C ))i ≤ j ≤ k ) J tm K ♯ Γ ( J tm K ′ ) ♯ Γ Î ≤ i ≤ n ( f J A i K ( C ) ) ( Γ ×h J A ij K ( C )i ≤ j ≤ ki ) ( f J B K ( C ) ) ( Γ ×h J B j K ( C )i ≤ i ≤ k ) C = h C , . . . , C m i ∈ S m h ( C ) def = h h ( C ) , . . . , h ( C m )i Figure 4.
Elementary term algebra coherenceinitial, we need a notion of homomorphism. This necessarilyinvolves a compatibility condition between algebraic termstructures.Categorically, this is made somewhat difficult to expressby the fact that two typed term structures for the samesignature may be algebras for polynomial endofunctors ondifferent presheaf categories, depending on their cartesian O ty -typed context structures. To reconcile them, we willmake use of the following lemma. Lemma 5.4.
Let ( C , τ : T → S ) and ( C ′ , τ ′ : T ′ → S ′ ) bemodels, and let ( H : C → C ′ , h : S → S ′ ) be a cartesian O ty -typed context structure homomorphism between them(Definition 3.4). Then there is a canonical naturaltransformation as follows. b C ′ / S ′ b C / S b C ′ / S ′ b C / S O tm O ′ tm h ∗ ◦(−) Hh ∗ ◦(−) H Definition 5.5. A homomorphism of models for a simplytyped syntax, from a model ( C , τ : T → S ) to a model ( C ′ , τ ′ : T ′ → S ′ ) , consists of • a cartesian O ty -typed context structurehomomorphism ( H : C → C ′ , h : S → S ′ ) ; • a natural transformation f : T → T ′ H ,such that the following diagrams, term-type coherence (left)and term algebra coherence (right), commute: T T ′ HS S ′ hτ τ ′ Hf O tm ( T ) O tm ( h ∗ ( T ′ H )) h ∗ ( O ′ tm ( T ′ ) H ) T h ∗ ( T ′ H ) J tm K f y O tm ( f y ) (Lemma 5.4) h ∗ ( J tm K ′ H ) where f y is the mediating morphism as in the following di-agram. T h ∗ ( T ′ H ) T ′ HS S ′ f y τ ′ Hτ hh ∗ ( τ ′ H ) y f The term algebra coherence diagram expresses that f y isan O tm -algebra homomorphism. This equivalentlyexpresses that f is a form of term algebra heteromorphismas in the following diagram. O tm ( T ) O tm ( h ∗ ( T ′ H )) h ∗ ( O ′ tm ( T ′ ) H ) O ′ tm ( T ′ ) HT T ′ H O tm ( f y ) (Lemma 5.4) J tm K J tm K ′ Hf In elementary terms, this corresponds to the coherence con-dition expressed in Figure 4. This resolves the compatibilitydifficulty described earlier.
Example 5.6.
For any cartesian O ty -typed context struc-ture homomorphism ( H , h ) , there is a canonical model ho-momorphism ( H , h , v ) for v : V → V ′ H given by the actionof H : v Γ (cid:0) A , ρ : Γ → h A i (cid:1) def = (cid:0) h ( A ) , H ( ρ ) : H ( Γ ) → h h ( A )i (cid:1) Models of simply typed syntax and theirhomomorphisms, for a simply typed syntax O , form acategory S O . Theorem 5.7. S O has an initial object.Proof. Let J ty K : O ty ( S ) → S be the initial O ty -algebra andlet C be the free cartesian O ty -typed context structure on S as in Proposition 3.5. The slice category b C / S is cocompleteand the polynomial endofunctor O tm is finitary(Proposition 4.13). Thus, we have an initial O tm -algebra J tm K : O tm ( τ : T → S ) −→ ( τ : T → S ) . Then M def = ( C , J ty K , τ : T → S , J tm K ) is a model for the signature O .Let ( C ′ , J ty K ′ , τ ′ : T ′ → S ′ , J tm K ′ ) be a model of simplytyped syntax for the signature O . There is a unique athanael Arkor and Marcelo Fiore O ty -homomorphism h : S → S ′ , by initiality of S , and H : C → C ′ is uniquely determined by the freeness of C .Furthermore, there is a unique O tm -homomorphism f : T → T ′ H satisfying the coherence conditions by theinitiality of τ : T → S . Finally, ( H , h , f ) is a unique modelhomomorphism and M is therefore initial. (cid:3) The initial object in S O is the syntactic model . Indeed, ac-cording to the viewpoint of initial-algebra semantics [21],syntactic models are precisely initial ones, for these have acanonical compositional interpretation into all models and,as such, uniquely characterise any concrete syntactic con-struction up to isomorphism. Here, it is further possible tomake the finitary semantic construction of Theorem 5.7 ex-plicit to demonstrate its coincidence with familiar syntacticconstructions. O tm -algebras represent a notion of terms with (sorted andbinding) algebraic structure. However, there are still twoimportant concepts that are missing: that of(capture-avoiding) substitution, and that of equations.Substitution must be described before defining equationson terms, as many equational laws (such as the β -equalityof the simply-typed λ -calculus) involve thismeta-operation. Substitution is an important metatheoreticconcept even besides this, and is necessary to define themulticategorical composition operation that will appear insome of the models of simple type theories (Definition 9.1).To begin to talk about substitution, one must have a no-tion of variables as terms , corresponding to the followingstructure. V TS ν var τ This structure is not a term operator: it may instead be addedby considering free O tm -algebras on the typed term struc-ture of variables, ν : V → S .Substitution is traditionally given in one of two forms:single-variable substitution (typically denoted t [ u / x ] ) andmultivariable substitution (in which terms must be givenfor every variable in context). When the category ofcontexts is freely generated, these notions are equivalent.In our more general setting single-variable substitution isthe appropriate primitive notion.One may present substitution as an operation given bythe following rule. Γ , x : A ⊢ t : B Γ ⊢ u : A subst Γ ⊢ t [ u / x ] : B It corresponds to the polynomial below, according to thegeneral description of Section 4.3. S [ π , π ] ←−−−−− V × S + S [ ν × id , id ] −−−−−−−→ S π −−→ S An algebra for the functor induced by this polynomial isgiven explicitly by a morphism subst in b C / S as in the dia-gram below. T V × T + T × S Ý A , B ∈ S T BV A × T A TS V × S + S S S [ ν × id , id ][ π , π ] π τ τ subst [ π , π ] y τ × id + τ × id Here, for expository purposes, we shall equivalently con-sider the structure as given by a family of morphisms in b C , subst A , B : T BV A × T A → T B ( A , B ∈ S ) which is closer to the syntactic intuition.The substitution operator must obey equational laws ( cf. [18, Definition 3.1] and [19, Section 2.1]). This structuremust be described semantically, as it makes use of theimplicit cartesian structure of the categories of contexts,which is not available syntactically. Specifically, we requirethe following diagrams to commute. They correspondrespectively to trivial substitution, left and right identities,and associativity. T A × T B T AV B × T B T A wk × id π subst B , A × T A T AV A × T A T Aλ ( var A )× id subst A , A π T BV A × V A T BV A × T A T B id × var A subst A , B contr ( T C V B × V A × T BV A ) × T A T C V A × T A ( T C V B × V A × T A ) × ( T BV A × T A ) T C ( T C V A × V B × T AV B ) × ( T BV A × T A ) T C V B × T B ( exch × wk )× id subst VAB , C × id subst VBA , C × subst A , B subst A , C subst B , C str The morphism exch is given by T γ where γ : X × Y (cid:27) −→ Y × X is the cartesian symmetry; wk by X ! : X → X Y ; and contr by the evaluation. By the extension structure of cartesian Σ ty -typed context structures, they respectively correspondto the admissible syntactic operations of exchange, weaken-ing, and contraction. The map str is the canonical strengthof products and the map subst PA , B is the composite T BV A × P × T AP (cid:27) −→ ( T BV A × T A ) P ( subst A , B ) P −−−−−−−−−→ T B P
Crucially, substitution must also commute with all the op-erators of the theory: for every unparameterised operator o lgebraic models of simple type theories as in Figure 1, we require the following diagram to commutefor all C ∈ S m and D ∈ S , where E i def = Î ≤ j ≤ k i V J A ij K ( C ) . (cid:0) Î ≤ i ≤ n T J A i K ( C ) E i (cid:1) V D × T D T J B K ( C ) V D × T D Î ≤ i ≤ n T J A i K ( C ) V D × E i × T D E i Î ≤ i ≤ n T J A i K ( C ) E i T J B K ( C )( J o K ♯ ) VD × id subst D , J B K ( C ) Î ≤ i ≤ n subst EiD , J Ai K ( C ) J o K ♯ (cid:27) ◦( (cid:27) ×h wk i i ≤ i ≤ n ) Models of simply typed syntax with unparameterisedterm operators may be extended to incorporate variableand substitution structure; together with homomorphismsthat preserve this structure, they form a category.
Proposition 6.1.
For a term signature O tm with unparame-terised operators, models of simply typed syntax with vari-able and substitution structure over a fixed cartesian typedcontext structure admit free constructions, and thereby gen-erate a free monad which we denote by O ⊛ tm . Proposition 6.2. O ⊛ tm -algebras for the free cartesian ([ ] , [ ]) -typed context structure on a single sort(Proposition 3.5) are, equivalently, O tm -substitutionalgebras [18]. Theorem 6.3 (Substitution lemma, cf. [11, 18]) . For a fixed Σ ty -algebra and the free cartesian Σ ty -typed context structurethereon, provided that the signature O tm contains only unpa-rameterised operators, the free O ∗ tm -algebra on ν : V → S andthe initial O ⊛ tm -algebra are isomorphic. From the syntactic viewpoint, this means that substitu-tion is admissible: adding a substitution operator to a sim-ply typed syntax leaves the associated terms unchanged, be-cause a term involving substitution is always equal to onethat does not involve substitution.
Proposition 6.4.
In the presence of weakening andexchange (present in the simple type theories we considerhere) and substitution, parameterised term operators(Definition 4.7) are admissible.
Equations on terms may now be treated, analogously tothose on types, with the proviso that one must keep trackof sorts and variable contexts. In particular, we areinterested in terms parameterised by a number of typemetavariables, and term metavariables in extendedcontexts [11, 22].
Notation 7.1.
For m ∈ N , let K m denote the free Σ ty -algebra Σ ∗ ty ( m ) on a set of type metavariables m and let K m denote the category of contexts Cart ( K m ) of the free cartesian Σ ty -typed context structure on a set of typemetavariables m (Proposition 3.5). Definition 7.2. An O tm -term equation is given by a triple (cid:0) m ∈ N , (cid:0) A , . . . A n → B (cid:1) ∈ ar (cid:0) O ∗ ty ( m ) (cid:1) , ( l , r ) (cid:1) (9)with l , r : Î ≤ j ≤ k V B j → O ⊛ tm ( p : P → K m ) B a parallel pairof morphisms in c K m for P def = Þ ≤ i ≤ n Ö ≤ j ≤ k i V A ij p (cid:0) h i , ( ρ , . . . , ρ k i )i (cid:1) def = A i where A i = ( A i , . . . , A ik i ) A i and B = ( B , . . . , B k ) B .The parallel pair equivalently corresponds to a pair ofterms in O ⊛ tm ( P ) B (h B , . . . , B k i) which may be syntacticallypresented as in Figure 5. Definition 7.3. An equational term signature , typically de-noted Σ tm , is given by a term operator signature O tm and alist E tm of O tm -term equations.Fix an O tm -term equation as in (9) and consider an O tm -algebra in b C / S : J tm K : O tm ( τ : T → S ) −→ ( τ : T → S ) (10)Every C ∈ S m freely induces a homomorphism ( H , h ) : ( K m , K m ) → ( C , S ) , and every morphism t in c K m / K m as below P h ∗ ( T H ) K m t p h ∗ ( τ H ) (11)freely induces the following situation, analogously to (1). O tm ( O ⊛ tm ( P )) O tm ( h ∗ ( T H )) O ⊛ tm ( P ) h ∗ ( T H ) P η ψ t J tm K ⊛ h ∗ ( J tm K H ) ◦ (Lemma 5.4) O tm ( ψ t ) t Definition 7.4. An O tm -algebra as in (10) satisfies an O tm -term equation as in (9) whenever, for all C and t as inthe preceding discussion, ψ t ◦ l = ψ t ◦ r .A morphism t as in (11) corresponds to a family t i ∈ T J A i K ( C ) (h J A i K ( C ) , . . . , J A ik i K ( C )i) ( ≤ i ≤ n ) As such, it provides a valuation for the term placeholdersof the terms in the equation. Indeed, the evaluation of ψ t at u ∈ O ⊛ tm ( P ) B (h B , . . . , B k i) is the term resulting from a meta-substitution operation replacing the term placeholders in u with the concrete terms ( t i ) ≤ i ≤ n . athanael Arkor and Marcelo Fiore Γ , x : A , . . . , x k : A k ⊢ t : A · · · Γ , x n : A n , . . . , x nk n : A nk n ⊢ t n : A n Γ , y : B , . . . , y k : B k ⊢ l ≡ r : B Figure 5.
Natural deduction rule for a term equation
Definition 7.5.
Given an equational term signature Σ tm = ( O tm , E tm ) , a Σ tm -algebra is an O tm -algebra that satisfies theequations of E tm .Equational term signatures (like equational type signa-tures) are an entirely syntactic notion and correspond ex-actly to systems of natural deduction rules presenting a sim-ple type theory. We give examples. Example 7.6.
Equational presentations in multisorteduniversal algebra [5] are examples of equational termsignatures, whose operators are nonbinding andunparameterised.
Notation 7.7.
We will informally denote by t : ( x : A ) B aterm metavariable t of type B in contexts extended by a freshvariable x of type A , reminiscent of the notation for second-order arities (Notation 4.6). The types of bound variables interm operators, and of terms themselves, may be inferred,and are elided. Example 7.8 ( β / η rules for the simply-typed λ -calculus) . A , B : ∗ ⊲ t : ( x : A ) B , a : A ⊢ app (cid:0) abs (cid:0) ( z ) t [ z / x ] (cid:1) , a (cid:1) ≡ t [ a / x ] A , B : ∗ ⊲ f : Fun ( A , B ) ⊢ abs (cid:0) ( x ) app ( f , x ) (cid:1) ≡ f Example 7.9 (Computational λ -calculus [27]) . The follow-ing extends the simply-typed λ -calculus. ⊲ T : ∗ → ∗ A : ∗ ⊲ return : A → T ( A ) A , B : ∗ ⊲ bind : T ( A ) , ( A ) T ( B ) → T ( B ) A , B : ∗ ⊲ a : A , f : ( x : A ) T ( B )⊢ bind (cid:0) return ( a ) , ( z ) f [ z / x ] (cid:1) ≡ f [ a / x ] A : ∗ ⊲ m : T ( A ) ⊢ bind (cid:0) m , ( x ) return ( x ) (cid:1) ≡ mA , B : ∗ ⊲ m : T ( A ) , f : ( x : A ) T ( B ) , д : ( y : B ) T ( C )⊢ bind (cid:0) m , ( a ) bind (cid:0) f [ a / x ] , ( b ) д [ b / y ] (cid:1) (cid:1) ≡ bind (cid:0) bind ( m , ( a ) f [ a / x ]) , ( b ) д [ b / y ] (cid:1) Models of simply typed syntax with variable and substi-tution structure may be restricted to algebras for equationalterm signatures.
Proposition 7.10.
Algebras for equational termsignatures Σ tm with unparameterised operators over afixed cartesian typed context structure admit freeconstructions, and thereby generate a free monad, whichwe denote by Σ ⊛ tm . The monad associated to an equational term signature ( O tm , [ ]) is the free O tm -monad with variable and substitu-tion structure O ⊛ tm . For any list of O tm -term equations E tm ,there is a canonical quotient monad morphism O ⊛ tm ։ Σ ⊛ tm . Simple type theories extend simply typed syntax by incor-porating variable, substitution, and equational structure.
Definition 8.1. A simple type theory consists of: • an equational type signature Σ ty ; • an equational term signature Σ tm for Σ ty . Definition 8.2. A model for a simple type theory consistsof • a Σ ∗ ty -algebra J ty K : Σ ∗ ty ( S ) → S ; • a cartesian Σ ty -typed context structure C for S ; • a Σ ⊛ tm -algebra J tm K : Σ ⊛ tm ( τ : T → S ) → ( τ : T → S ) .In particular, the type and term algebras both satisfy thespecified equations. Definition 8.3. A homomorphism of models for a simpletype theory is a homomorphism ( H , h , f ) for the underly-ing simply typed syntax such that f preserves the variablestructure and is a heteromorphism for the substitution struc-ture.Models of simple type theories and theirhomomorphisms, for a simple type theory Σ , form acategory S Σ . Theorem 8.4. S Σ has an initial object. The initial object is the syntactic model . It is given by aconstruction analogous to the one in Theorem 5.7, takingProposition 7.10 into account.
The classes of models we have considered so far are verygeneral. First, contexts must be closed under extension, butmay not necessarily be lists of sorts. More importantly, sub-stitution is not inherent in simply typed syntax, which al-lowed us to consider models with and without substitution:it is only by making this distinction that we are able to provemetatheoretic properties regarding substitution, such as inTheorem 6.3. However, one typically wishes to consider sim-ple type theories that do have an associated notion of sub-stitution, along with contexts that are lists. In this setting, lgebraic models of simple type theories we can reformulate the models to be more familiar to themodels dealt with in categorical algebra (see e.g. Crole [7]).
Definition 9.1.
A model of simple type theory is multisub-stitutional if the embedding of the set of sorts in the categoryof contexts presents the latter as the strict cartesian comple-tion of the former.Multisubstitutional models have list-like contexts and ad-mit a multivariable substitution operation [18] in additionto, and induced by, the single-variable substitution opera-tion of Section 6. In fact, we have the following result.
Theorem 9.2.
Multisubstitutional models of simple type the-ories with empty type operator signatures are equivalent tocartesian multicategories with corresponding structure.
We sketch the idea. There is an equivalence taking sucha multisubstitutional model ( C , τ : T → S ) to a cartesianmulticategory M , with object set S ; multihoms M ( A , . . . , A n ; B ) = T B (h A , . . . , A n i) ; identities arisingfrom the variable structure; composition given by themultivariable substitution operation (or, equivalently, byiterated single-variable substitution); and cartesianmulticategory structure given by the functorial action ofthe presheaf T along the exchange, weakening, andcontraction structure of C . Model homomorphisms definecartesian multifunctors.The algebraic structure on T induces structure on M ,where each term operator induces a pair of functors(corresponding to the premisses and conclusion), naturaltransformations between which correspond tointerpretations of the operator.There are a variety of notions equivalent to cartesianmulticategories, such as many-sorted abstract clones andmultisorted Lawvere theories, giving correspondingversions of Theorem 9.2 for each notion. Relevant forfuture work on polynomial models of dependent typetheories is the relationship with categories withfamilies [8]. We note that the relationship withsimply-typed categories with families in Proposition 5.3extends to incorporate operators and equations. However,care must be taken: in the context of categories withfamilies, type theoretic structure is typically expressedthrough generalised algebraic theories, which permitoperators that are not natural in a categorical sense; while,conversely, such unnatural operators are forbidden in thecurrent framework.Theorems 8.4 and 9.2 provide a general systematic con-struction of the classifying cartesian multicategory of anysimple type theory. In the context of universal algebra, wehave the following. Corollary 9.3.
The initial model of the simple type theoryfor an equational presentation in universal algebra is, equiv-alently, its abstract clone.
Beyond universal algebra, we have a kind of “generalisedLambek correspondence” between models of simple typetheories and structured cartesian multicategories. When thesimple type theory has finite products, the classifying carte-sian multicategory is representable and hence equivalent toa cartesian category. In particular, we recover the classicalLambek correspondence.
Corollary 9.4 (Lambek correspondence) . The initial modelof the simple type theory for the simply-typed λ -calculus witha set of base types B is, equivalently, the free cartesian-closedcategory on B . References [1] Michael Abbott, Thorsten Altenkirch, and Neil Ghani. 2003. Cate-gories of containers. In
International Conference on Foundations of Soft-ware Science and Computation Structures . Springer, 23–38.[2] Jiří Adámek, Jiří Rosický, and Enrico Maria Vitale. 2010.
Algebraictheories: A categorical introduction to general algebra . Vol. 184. Cam-bridge University Press.[3] Steve Awodey. 2018. Natural models of homotopy type theory.
Math-ematical Structures in Computer Science
28, 2 (2018), 241–286.[4] Steve Awodey and Clive Newstead. 2018. Polynomial pseudomonadsand dependent type theory. arXiv preprint arXiv:1802.00997 (2018).[5] Garrett Birkhoff and John D Lipson. 1970. Heterogeneous algebras.
Journal of Combinatorial Theory
8, 1 (1970), 115–133.[6] Simon Castellan, Pierre Clairambault, and Peter Dybjer. 2019. Cat-egories with Families: Unityped, Simply Typed, and DependentlyTyped. arXiv preprint arXiv:1904.00827 (2019).[7] Roy L Crole. 1993.
Categories for types . Cambridge University Press.[8] Peter Dybjer. 1995. Internal type theory. In
International Workshop onTypes for Proofs and Programs . Springer, 120–134.[9] Marcelo Fiore. 2002. Semantic analysis of normalisation by evaluationfor typed lambda calculus. In
Proceedings of the 4th ACM SIGPLANInternational Conference on Principles and Practice of Declarative Pro-gramming . ACM, 26–37.[10] Marcelo Fiore. 2008. Algebraic Type Theory. (2008).
Unpublished(Accessed 2020-05-01).[11] Marcelo Fiore. 2008. Second-order and dependently-sorted abstractsyntax. In .IEEE, 57–68.[12] Marcelo Fiore. 2011. Algebraic Foundations for Type Theories. (2011).
Talk given atthe 18th Workshop of Types for Proofs and Programs (Accessed 2020-05-01).[13] Marcelo Fiore. 2012. Discrete generalised polynomial functors. In
International Colloquium on Automata, Languages, and Programming .Springer, 214–226.[14] Marcelo Fiore. 2012. Discrete generalised polynomial functors.(2012).
Talkpresented at ICALP 2012 (Accessed 2020-05-01).[15] Marcelo Fiore and Makoto Hamana. 2013. Multiversal polymorphic al-gebraic theories: Syntax, semantics, translations, and equational logic.In
Proceedings of the 28th Annual ACM/IEEE Symposium on Logic inComputer Science . IEEE Computer Society, 520–529.[16] Marcelo Fiore and Chung-Kil Hur. 2009. On the construction of freealgebras for equational systems.
Theoretical Computer Science
International Workshop on Computer Science Logic . Springer,320–335.13 athanael Arkor and Marcelo Fiore [18] Marcelo Fiore, Gordon Plotkin, and Daniele Turi. 1999. Abstract syn-tax and variable binding. In
Proceedings of the 14th Symposium onLogic in Computer Science . IEEE, 193–202.[19] Marcelo Fiore and Sam Staton. 2014. Substitution, jumps, and alge-braic effects. In
Proceedings of the Joint Meeting of the Twenty-ThirdEACSL Annual Conference on Computer Science Logic (CSL) and theTwenty-Ninth Annual ACM/IEEE Symposium on Logic in Computer Sci-ence (LICS) . ACM.[20] Nicola Gambino and Joachim Kock. 2013. Polynomial functors andpolynomial monads. In
Mathematical Proceedings of the CambridgePhilosophical Society , Vol. 154. Cambridge University Press, 153–192.[21] J.A. Goguen, J.W. Thatcher, and E.G. Wagner. 1976.
An Initial Alge-bra Approach to the Specification, Correctness, and Implementation ofAbstract Data Types . IBM Thomas J. Watson Research Division.[22] Makoto Hamana. 2004. Free Σ -monoids: A higher-order syntax withmetavariables. In Asian Symposium on Programming Languages and Systems . Springer, 348–363.[23] Joachim Lambek. 1980. From Lambda-calculus to Cartesian ClosedCategories.
To H. B. Curry: Essays on Combinatory Logic, Lambda Cal-culus and Formalism (1980), 376–402.[24] F. William Lawvere. 1963. Functorial semantics of algebraic theories.
Proceedings of the National Academy of Sciences of the United States ofAmerica
50, 5 (1963), 869.[25] Per Martin-Löf. 1984.
Intuitionistic type theory . Vol. 9.[26] Eugenio Moggi. 1988.
Computational lambda-calculus and monads .[27] Eugenio Moggi. 1991. Notions of computation and monads.
Informa-tion and computation
93, 1 (1991), 55–92.[28] Clive Newstead. 2018.
Algebraic models of dependent type theory . Ph.D.Dissertation. Carnegie Mellon University.[29] Mark Weber. 2015. Polynomials in categories with pullbacks.