Extended Initiality for Typed Abstract Syntax

Initial Semantics aims at interpreting the syntax associated to a signature as the initial object of some category of 'models', yielding induction and recursion principles for abstract syntax. Zsid\'o proves an initiality result for simply-typed syntax: given a signature S, the abstract syntax associated to S constitutes the initial object in a category of models of S in monads. However, the iteration principle her theorem provides only accounts for translations between two languages over a fixed set of object types. We generalize Zsid\'o's notion of model such that object types may vary, yielding a larger category, while preserving initiality of the syntax therein. Thus we obtain an extended initiality theorem for typed abstract syntax, in which translations between terms over different types can be specified via the associated category-theoretic iteration operator as an initial morphism. Our definitions ensure that translations specified via initiality are type-safe, i.e. compatible with the typing in the source and target language in the obvious sense. Our main example is given via the propositions-as-types paradigm: we specify propositions and inference rules of classical and intuitionistic propositional logics through their respective typed signatures. Afterwards we use the category--theoretic iteration operator to specify a double negation translation from the former to the latter. A second example is given by the signature of PCF. For this particular case, we formalize the theorem in the proof assistant Coq. Afterwards we specify, via the category-theoretic iteration operator, translations from PCF to the untyped lambda calculus.


Introduction
Initial Semantics characterizes the set of terms of a language via a universal propertynamely as an initial object in some category -, and gives a category-theoretic account of the iteration principle it is equipped with.By working in a suitable category, one can specify additional structure and properties on the syntax.As an example, the initial object in our category is by definition equipped with a substitution operation, due to our use of monads (cf.Def.2.1, Exs.2.9, 2.13).Furthermore, this substitution is by construction type-safe.Initiality also provides an iteration principle which allows to specify maps as initial morphisms on the the set of terms of a syntax.The main focus of this paper is to obtain a sufficiently general iteration operator that allows to specify translations between 2 B. AHRENS terms over different sets of object types (to which we also refer as sorts) as such initial morphisms.
An important property of translations between programming languages is that they should preserve the meaning of programs.While the present work does not consider this aspect -it merely treats the syntactic part -, we outline our ideas concerning faithfulness of translation with respect to meaning in Sec. 6.
In Sec.1.1 we explain initiality for syntax without binding by means of an example and present our view on syntax with variable binding and sorts.Related work is reviewed in Sec.1.2.In Sec.1.3 we give an overview of the paper.
1.1.1.Natural Numbers.Consider the category N an object of which is a triple (X, Z, S) of a set X, a constant Z ∈ X and a map S : X → X.A morphism to another such (X , Z , S ) is a map f : X → X such that This category has an initial object (N, Zero, Succ), and a map f from N to a set X can be specified by giving an element Z ∈ X and a map S : X → X.This way of specifying the map f is an iteration principle for N resulting from its initiality in the category N .Our work consists in providing, via initiality, a category-theoretic iteration operator for typed syntax with variable binding, similar in spirit to that for the natural numbers.In the rest of this section we consider some aspects that arise when passing from our introductory example about natural numbers to syntax with variable binding and types.
1.1.2.Variable Binding.For syntax with variable binding, we consider the set of terms to be parametrized by a context, i.e. a set of variables, whose elements may appear freely in those terms.The terms of the untyped lambda calculus, for instance, can be implemented in the proof assistant Coq [Coq10] as the following parametrized datatype: Inductive ULC (V : Type) : Type := | Var : where option V stands for an extended context obtained by enriching the context V with a new distinguished variable -the variable which is bound by the Abs constructor.
The map V → ULC(V ) is in fact functorial: given a map f : V → W , the map ULC(f ) : ULC(V ) → ULC(W ) renames any free variable v ∈ V in a term by f (v), yielding a term with free variables in W . Accordingly, instead of sets and maps of sets as for the introductory example, we consider functors and natural transformations between them.
1.1.3.Adding Types.The interest of considering typed syntax is twofold: firstly, for programming languages, typing rules contain information of how to plug several terms together in semantically meaningful ways, and ensure properties such as termination.Secondly, via the propositions-as-types paradigm, logics may be considered as typed syntax, where propositions are viewed as types, and a term p : P of type P thus denotes a proof p of proposition P .In this vein, the inference rules correspond to term constructors, i.e. they are the basic bricks from which one builds terms -proofs -according to plugging rules.The premises of such an inference rule thus are represented by the inputs of the constructor, whereas the conclusion is represented by its output type.
In the present work we consider both applications of types: our main example, a logic translation from classical to intuitionistic logic (cf.Sec.4), works through the propositions-astypes paradigm.As a running example throughout this work we consider typed programming languages.
Type systems exists with varying features, ranging from simply-typed syntax to syntax with dependent types, kinds, polymorphism, etc.By simply-typed syntax we mean a non-polymorphic syntax where the set of types is independent from the set of terms, i.e. type constructors only take types as arguments, In more sophisticated type systems types may depend on terms, leading to more complex definitions of arities and signatures.The present work is only concerned with simply-typed languages.
One way to add types would be to make them part of the syntax, as in "λx : ι.x + 4".However, for simple type systems it is possible to separate the worlds of types and terms and consider typing as a map from terms to types, thus giving a simple mathematical structure to typing.How can we be sure that our terms are well-typed?Despite the separation of types and terms we still want typing to be tightly integrated into the process of building terms, in order to avoid constructing ill-typed terms.Separation of terms and types seems to contradict this goal.The answer lies in considering not one set of terms, but a family of sets, indexed by the set of object types.Term constructors then can be "picky" about what terms they take as arguments, accepting only those terms that have the suitable type.We also consider free variables to be equipped with an object type.Put differently, we do not consider terms over one set of variables, but over a family of sets of variables, indexed by the set of object types.We illustrate such a definition of a family of terms in the proof assistant Coq [Coq10] using the example of the simply-typed lambda calculus SLC: Example 1.1 (Syntax of SLC).Let be the set of types of the simply-typed lambda calculus.For each "typed set" V ∈ [T SLC , Set] and t ∈ T SLC we denote by V t := V (t) the set associated to object type t ∈ T SLC .Hence SLC(V ) t denotes the set of lambda terms of type t with free variables in V .In the following Coq code excerpt we write T for T SLC .
Here V * r is Coq notation for V + { * r}, which is the family of sets V enriched with a new distinguished variable of type r ∈ T SLC -the variable which is bound by the Abs(r, s) This method of defining exactly the well-typed terms by organizing them into a type family parametrized by object types is called intrinsic typing [BHKM11] -as opposed to the extrinsic typing, where first a set of raw terms is defined, which is then filtered via a typing predicate.Intrinsic typing delegates object level typing to the meta language type system, such as the Coq type system in Ex. 1.1.In this way, the meta level type checker (e.g.Coq) sorts out ill-typed terms automatically: writing such a term yields a type error on the meta level.Furthermore, the intrinsic encoding comes with a much more convenient recursion principle; a map to any other type can simply be defined by specifying its image on the well-typed terms.When using extrinsic typing, a map on terms would either have to be defined on the set of raw terms, including ill-typed ones, or on just the well-typed terms by specifying an additional propositional argument expressing the welltypedness of the term argument.Benton et al. give detailed explanation about intrinsic typing in a recently published paper [BHKM11].
1.1.4.Substitution.Syntax with variable binding always comes with a (capture-avoiding) substitution operation.Fiore, Plotkin and Turi [FPT99] model substitution and its properties using the notion of monoid.An alternative point of view is given by monads: a monad (Def.2.1) is an endofunctor with extra structure, and it is this additional structure that captures substitution (cf.Ex. 2.9), as exhibited by Altenkirch and Reus [AR99].We review the monad structure on ULC (Ex.2.9) and SLC (Ex.2.13).
1.2.Related Work.Initial Semantics for untyped syntax without variable binding was first considered by Birkhoff [Bir35].Goguen et al. [GTWW77] give an overview over the literature about initial algebra and spell out explicitly the connection between initial algebras and abstract syntax.
When passing to syntax with variable binding, the question of how to model binding arises.We give a possibly non-exhaustive list of techniques for binder representation: (1) Nominal syntax using named abstraction; (2) Higher-Order Abstract Syntax (HOAS), e.g.lam : (T → T ) → T and its weak variant, e.g.lam : (var → T ) → T ; (3) Nested datatypes as presented in [BM98].In the following, the numbers given in parentheses indicate the way variable binding is modeled, according to the list given above.Initial semantics for untyped syntax were presented by Gabbay and Pitts [GP99, (1)], Hofmann [Hof99, (2)] and Fiore et al. [FPT99,(3)].Hirschowitz and Maggesi [HM07,(3)] prove an initiality result for arbitrary untyped syntax based on the notion of monad.
Some of the mentioned lines of work have been extended to integrate semantic aspects in form of reduction relations on terms into initiality results: Hirschowitz and Maggesi [HM07] characterize the terms of the lambda calculus modulo beta and eta reduction as an initial object in some category.In another work [Ahr11], we extend Hirschowitz and Maggesi's approach via monads to encompass semantics in form of reduction rules, specified through inequations, by considering relative monads [ACU10] over a suitable functor from sets to preorders.Fiore and Hur [FH07] extended Fiore et al.'s approach to "second-order universal algebras".In particular, Hur's PhD thesis [Hur10] is dedicated to this extension.1.3.Summary of the Paper.We prove an initiality result for simply-typed syntax which provides a category-theoretic iteration operator for translations between languages over different sets of sorts.
We define typed signatures in order to specify the types and terms of simply-typed languages.To any such typed signature we associate a category of representations -"models" -of this signature.Our main theorem states that this category has an initial object, which integrates the types and terms freely generated by the signature.Initiality yields an iteration operator which allows to conveniently and economically specify translations between languages over different sets of sorts.
We give two examples of translations via such an iteration operator: firstly, via the proposition-as-types paradigm we consider classical and intuitionistic propositional logic as simply-typed languages.We present the typed signature for both of these logics and specify a double negation translation from classical to intuitionistic logic via the category-theoretic iteration operator (Sec.4).Secondly, we present the typed signature of the programming language PCF, a simply-typed programming language introduced by Plotkin [Plo77].For this particular typed signature, we have formalized the initiality theorem in the proof assistant Coq [Coq10].Afterwards we have specified two different representations of PCF in the untyped lambda calculus ULC, yielding -by initiality -two translations from PCF to ULC.The formalization is presented in Sec. 5.In the formalization these translations are Coq functions and hence executable.The Coq theory files as well as online documentation are available online1 .1.4.Synopsis.In the second section we review the definitions of monads and modules over monads with their respective morphisms.We recall some constructions on monads and modules, which will be of importance in what follows.The third section introduces our notions of arity, typed signature and representations of typed signatures.We then prove our main result.In the fourth section, we present our main example: we specify the propositions and proofs of classical and intuitionistic logic via their respective typed signatures, and define a translation from the former to the latter logic via initiality.

B. AHRENS
The fifth section gives a brief overview of the formalization in the proof assistant Coq of the theorem instantiated for the signature of PCF, as well as two translations from PCF to the untyped lambda calculus via initiality.Some extensions we are working on are explained in the last section.

Monads & Modules
We state the widely known definition of monad and the less known definition of module over a monad.Modules have been used in the context of Initial Semantics by Hirschowitz and Maggesi [HM07, HM10] and Zsidó [Zsi10].Monad morphisms are in fact colax monad morphisms, as presented, for instance, by Leinster [Lei04].
Our definition of colax monad morphisms and their transformations is taken from Leinster's book [Lei04]: Definition 2.4 (Colax Monad Morphism).Let (T, η, µ) be a monad on the category C and (T , η , µ ) be a monad on the category D. A colax morphism of monads (C, T ) → (D, T ) is given by • a functor F : C → D and • a natural transformation γ : F T → T F such that the following diagrams commute: From now on we will simply say "monad morphism over F " when speaking about a colax monad morphism with underlying functor F .We will not use any other kind of monad morphism.
Definition 2.5 (Composition of Monad Morphisms).Suppose given a monad morphism as in Def.2.4.Given a third monad (T , η , µ ) on category E and a monad morphism (F , γ ) : (T , η , µ ) → (T , η , µ ), we define the composition of (F, γ) and (F , γ ) to be the monad morphism given by the pair consisting of the functor F F and the transformation The verification of the necessary commutativity properties is done in the Coq library, cf.colax_Monad_Hom_comp.
Definition 2.6 (Transformation).Given two morphisms of monads ) is given by a natural transformation β : F → F such that the following diagram commutes: Definition 2.7 (2-Category of Monads, [Lei04]).We call Mnd colax the 2-category an object of which is a pair (C, T ) of a category C and a monad T on C. A morphism to another object (D, T ) is a colax monad morphism (F, γ) Notation 2.8.For any category C, we write Id C for the object (C, Id) of Mnd colax .
Example 2.9 (Monadic Syntax, Untyped).Syntax as a monad (using the Kleisli operation presented in Rem.2.3) was presented by Altenkirch and Reus [AR99]: consider the syntax of the untyped lambda calculus ULC as given in Sec.1.1.As mentioned there, the map V → ULC(V ) is functorial.We equip it with a monad structure: we define η as variable-asterm operation η V (v) := Var(v) ∈ ULC(V ) and the multiplication µ : ULC • ULC → ULC as flattening which, given a term of ULC with terms of ULC(V ) as variables, returns a term of ULC(V ).These definitions turn (ULC, η, µ) into a monad on the category Set.The Kleisli operation associated to this monad corresponds to a simultaneous substitution, cf.[AR99].

B. AHRENS
For reasons that are explained in Rem.2.14, we are particularly interested in monads over families of sets (Def.2.10) and monad morphisms over retyping functors (Def.2.11).Definition 2.10 (Category of Families).Let C be a category and T be a set, i.e. a discrete category.We denote by [T, C] the functor category, an object of which is a T -indexed family of objects of C. Given two families V and W , a morphism f : . We write V t := V (t) for objects and morphisms.Given another category D and a functor F : C → D, we denote by [T, F ] the functor defined on objects and morphisms as Definition 2.11 (Retyping Functor).Let T and T be sets and g : T → T be a map.Let C be a cocomplete category.We define the functor In particular, for any V ∈ [T, C] -considered as a functor -we have a natural transformation Remark 2.12 (Retyping as an Adjunction).An anonymous referee pointed out to us that the retyping functor g associated to g : T → T is the left Kan extension operation along g, that is, we have an adjunction where g * (W ) := W • g.The natural transformation ctype is the unit of this adjunction.
Given a map g as in Def.2.11, we interpret the map g : T → T as a translation of object sorts and the functor g as a "retyping functor" which changes the sorts of contexts and terms (and more generally, models of terms) according to the translation of sorts.
In Ex. 2.13 and Rem.2.14 we explain how we consider languages as monads and translations between languages as monad morphisms over retyping functors, respectively: Example 2.13 (Monadic Syntax, Typed).Consider the syntax of the simply-typed lambda calculus as presented in Ex. 1.1.Similarly to the untyped lambda calculus, the natural transformations η : Id → SLC and µ : SLC • SLC → SLC are defined as variable-as-term operation and flattening, respectively.These definitions turn (SLC, η, µ) into a monad on the category [T SLC , Set].
The previous example explains, how the terms of a language can be organized in a monad.Accordingly, a translation between two languages corresponds to a monad morphism: Remark 2.14.Suppose we have two monads, a monad P over [U, Set] and a monad Q over [V, Set] for sets U and V .We think of P and Q as term monads as in Ex. 2.13, i.e. the monads P and Q denote the terms of some programming language over types U and V , respectively.However, what follows is not restricted to such term monads.
A map -"translation" -from P to Q now consists, first of all, of a map of types g : U → V .The translation of terms f then should be compatible with the type translation g.During the term translation f we have to pass from the category [U, Set] -where the terms of P live -to the category [V, Set], where the terms of Q live.This passing is done via the retyping functor g associated to the type translation g.
Given a set of variables X ∈ [U, Set] typed over U , a translation of terms with free variables in X is specified via a morphism The intuition is that if we have a term t ∈ P (X) u , we translate at first its type u ∈ U to g(u), yielding a term t ∈ g(P X) g(u) .The term translation afterwards then is a morphism in the category [V, Set]: where instead of "f X " one should read "the component of f X corresponding to g(u)".
Putting this in category-theoretic terms, the family (f X ) X∈[U,Set] of morphisms forms a colax monad morphism f over the retyping functor associated to g, provided that f is compatible with the monadic structure on P and Q, i.e. with variables-as-terms and flattening operations.
A morphism of T -modules from (M, σ) to (M , σ ) then is given by a natural transformation β : M ⇒ M such that the following diagram commutes: Remark 2.17 (Kleisli Operation for Modules).Let T be a monad on a category C and (M, σ) be a T -module with codomain category D. Similarly to monads (cf.Rem.2.3), a Kleisli operation for modules, with type Modules over monads can equivalently be defined in terms of this Kleisli operation, cf.[AZ11].
We anticipate the constructions of the next section by giving some examples of modules and module morphisms: Example 2.18 (Tautological Module, Ex. 2.9 cont.).Any monad T on a category C can be considered as a module over itself, the tautological module.In particular, the monad of the untyped lambda calculus ULC (cf.Ex. 2.9) is a ULC-module with codomain Set.
Example 2.19.The map ULC : V → ULC(V ) , with V := V + { * }, inherits -from the tautological module ULC -the structure of a ULC-module, which we call the derived module of the module ULC.Also, the map The constructors of the untyped lambda calculus are, accordingly, morphisms of modules: Example 2.20 (Ex.2.19 cont.).The natural transformation verifies the diagram of module morphisms and is hence a morphism of ULC-modules from ULC × ULC to ULC.The natural transformation is a morphism of ULC-modules from ULC to ULC.
The meaning of the commutative diagrams for module morphisms is best explained in terms of the module Kleisli operation, the module substitution (cf.Def.2.17); for this equivalent definition, the notion of module morphism captures the distributivity property of substitution with respect to term constructors.A detailed explanation is given by Ahrens and Zsidó [AZ11].
Example 2.21.Given any t ∈ T SLC , the functor is canonically equipped with a module structure, where the natural transformation is simply the component in the fibre t of the multiplication µ of the monad SLC.This is an example of a module whose underlying functor is not an endofunctor.

Constructions on monads and modules.
We present some instances of modules which we will use in the next section.They were previously defined in Zsidó's thesis [Zsi10] and works of Hirschowitz and Maggesi [HM07,HM10].
The pullback operation extends to morphisms of modules and is functorial.Definition 2.25 (Induced module morphism).With the same notation as in the previous example, the monad morphism (F, γ) induces a morphism of T -modules -which we call γ as well - y y (D, Id).
+ 3 γ Indeed, the natural transformation γ verifies the corresponding diagram, as a consequence of the diagrams for monad morphisms it verifies.
Remark 2.28.The category [T, C] n consists of T n copies of [T, C], which do not interact.Due to the "markers" (t 1 , . . ., t n ) we can act differently on each copy, cf.e.g.Defs.2.34 and 2.37.The reason why we consider categories of this form is explained in Rem.3.17.
We generalize retyping functors to such categories with pointed indexing sets.When changing types according to a map of types g : T → U , the markers must be adapted as well: Definition 2.29.Given a map of sets g : T → U , by postcomposing the pointing map with g, the retyping functor generalizes to the functor Finally there is also a category where families of sets over different indexing sets are mixed together: Definition 2.30.Given a category C, we denote by T C the category where an object is a pair (T, V ) of a set T and a family V ∈ [T, C] of objects of C indexed by T .A morphism to another such (T , W ) is given by a map g : T → T and a morphism that is, family of morphisms, indexed by T , Let C have an initial object, denoted by 0 C .Given n ∈ N, we call n = (n, k → 0 C ) the element T C that associates to any 1 ≤ k ≤ n the initial object of C. We call T C n the slice category n ↓ T C.An object of this category consists of an object (T, V ) ∈ T C whose indexing set "of types" T is pointed n times, written (T, V, t 1 , . . ., t n ).We call T U n : T C n → Set the forgetful functor associating to any pointed family (T, V, t 1 , . . ., t n ) the indexing set T , in particular for the case that C is the category Set of sets.
Remark 2.31 (Picking out Sorts).Let 1 : T C n → Set denote the constant functor which maps objects to the terminal object 1 Set of the category Set.A natural transformation τ : 1 → T U n associates to any object (T, V, t) of the category T C n an element of T .Notation 2.32.Given a natural transformation τ : 1 → T U n as in Rem.2.31, we write i.e. we omit the argument * ∈ 1 Set of the singleton set.
2.3.1.Derivation.Roughly speaking, a binding constructor makes free variables disappear.Its input are hence terms "with (one or more) additional free variables" compared to the output, i.e. terms in an extended context.Derivation formalizes context extension.Let T be a set and u ∈ T an element of T .We define D(u) to be the object of [T, Set] such that We enrich the object V of [T, Set] with respect to u by setting that is, we add a fresh variable of type u to the context V .This yields a monad (_) * u on [T, Set].Moreover, given any monad P on [T, Set], we equip the functor V → V * u with a structure of an endomorphism on P : on a typed set V its natural transformation γ is defined as the coproduct map where [inl, inr] = id : Remark 2.33.In case the monad P denotes terms over sets of free variables as in Ex. 2.9, the map γ V defined in Eq. (2.1) sends a term t ∈ P V in a context V to its image in an extended context V * u , and the additional variable of type u to the term (in context V * u ) consisting of just this variable.
More generally, we derive with respect to a natural transformation Such τ associates to any V ∈ T Set n with a set of types T an object type t ∈ T .
Definition 2.34 (Derived Module).Let τ : 1 → T U n be a natural transformation.Given a set T and a monad P on [T, Set] n , the functor (_) * τ : V → V * τ (V ) is given the structure of a morphism of monads as in Eq. (2.1).Given any P -module M , we call derivation of M with respect to τ the module Remark 2.35.In the preceding definition the natural transformation τ : 1 → T U n supplies more data than necessary, since we only evaluate it on families of sets indexed by the fixed set T .However, in the next section we will derive different modules -each defined on a category [T, Set] n with varying sets T -with respect to one and the same natural transformation τ .
Example 2.36 (Ex.2.13 continued).We consider SLC (cf.Ex. 2.13) as the tautological module over itself.Given any element s ∈ T SLC , the derived module with respect to s, denotes the (typed) set of terms of SLC with variables in an extended context V * s .

B. AHRENS
2.3.2.Fibres.Given a set family V indexed by a (nonempty) set T , we sometimes need to pick the set of elements "of type u ∈ T ", that is, the set V (u) associated to u ∈ T .Given a monad P on a category C and a P -module M towards [T, Set], we define the fibre module of M with respect to u ∈ T to be the module which associates the fibre M (c)(u) to any object c ∈ C.This construction is expressed via postcomposition with a particular module: we define the fibre with respect to u ∈ T to be the monad morphism over the functor V → V (u).Postcomposition of the module M with this module then precisely yields the fibre module [M ] u of M with respect to u ∈ T .
Analogously to derivation we define the fibre more generally with respect to a natural transformation: Definition 2.37 (Fibre Module).Let the natural transformation τ be as in Def.2.34.We call fibre with respect to τ the monad morphism over the functor V → V τ V .Given a module M towards [T, Set] n (over some monad P ), we call the fibre module of M with respect to τ the module [M ] Example 2.38 (Ex.2.13 continued).We consider SLC as the tautological module over itself.Given any element t ∈ T SLC , the fibre module with respect to t, associates to any context V the set of simply-typed lambda terms of type t with variables in V .

Signatures & Representations
A simply-typed language is given by a pair (S, Σ) of signatures: an algebraic signature S specifying the types of the language, and a term-signature Σ which specifies terms that are typed over the set of object types associated to S. We call typed signature a pair (S, Σ) consisting of an algebraic signature S and a term-signature Σ over S.
3.1.Signatures for Types.Algebraic signatures were already considered by Birkhoff [Bir35].An example of (untyped) algebraic signature is given in the introduction.We review the general definition: Definition 3.1 (Algebraic Signature).An algebraic signature S is a family of natural numbers, i.e. a set J S and a map (carrying the same name as the signature) S : J S → N.For j ∈ J S and n ∈ N, we also write j : n instead of j → n.An element of J resp. its image under S is called an arity of S.
To any algebraic signature we associate a category of representations.We call representation of S any set U equipped with operations according to the signature S. A morphism of representations is a map between the underlying sets that is compatible with the operations on either side in a suitable sense.Representations and their morphisms form a category.We give the formal definitions: Definition 3.2 (Representation of an Algebraic Signature).A representation R of an algebraic signature S is given by • a set X and • for each j ∈ J S , an operation j R : X S(j) → X.In the following, given a representation R, we write R also for its underlying set.A representation T of S PCF is given by a set T and three operations, Definition 3.5 (Morphisms of Type-Representations).Given two representations T and U of the algebraic signature (J, S), a morphism from T to U is a map f : T → U on the underlying sets such that for any arity j ∈ J with S(j) = n we have Representations of S and their morphisms form a category.
Example 3.6 (Ex.3.4 continued).Given two representations T and U of S PCF , a morphism from T to U is a map f : T → U such that, for any s, t ∈ T , Next we prove that for any algebraic signature S, its category of representations has an initial object, whose underlying set Ŝ consists of the types freely generated by the signature.In particular, by initiality we obtain, for any representation R of S in a set U , a map from Ŝ to U .Lemma 3.7.Let (J, S) (or S for short) be an algebraic signature.The category of representations of S has an initial object Ŝ.
Proof.We cut the proof into small steps: • In a type-theoretic setting the set -also called Ŝ -which underlies the initial representation Ŝ is defined as an inductive set with a family of constructors indexed by J S : Ŝ ::= C : ∀j ∈ J, ŜS(j) → Ŝ .
That is, for each arity j ∈ J, we have a constructor C j : ŜS(j) → Ŝ.

B. AHRENS
• For each arity j ∈ J, we must specify an operation j Ŝ : ŜS(j) → Ŝ.We set that is, the representation j Ŝ of an arity n = S(j) is given precisely by its corresponding constructor.• Given any representation R of S, we specify a map i R : Ŝ → R between the underlying sets by structural recursion: for a ∈ ŜS(j) .That is, the image of a constructor function C j maps recursively on the image of the corresponding representation j R of R. • We must prove that i R is a morphism of representations, that is, that for any j ∈ J with Replacing j Ŝ by its definition yields that this equation is precisely the specification of i R , see above.• It is the diagram of Def.3.5 which ensures unicity of i R ; since any morphism of representations i : Ŝ → R must make it commute, one can show by structural induction that i = i R .More precisely: Example 3.8 (Ex.3.4 continued).The set T PCF underlying the initial representation of the algebraic signature S PCF is given by For any other representation R of S PCF the initial morphism i R : T PCF → R is given by the clauses 3.2.Signatures for Terms.We consider the simply-typed lambda calculus as specified in Ex. 1.1.Its terms could be specified by the signature: whose meaning is as follows: an arrow → separates domain and codomain data.The domain data specifies the input type; it consists of a list, where each list item corresponds to one argument.Each list item is itself a pair of a list -specifying the type of the variables bound in the corresponding argument -and an object type -the type of the argument.The codomain data specifies the output type of the associated constructor.This viewpoint is sufficient when considering models of SLC over the set T SLC of types of SLC.Indeed, Zsidó [Zsi10] defines signatures for terms precisely as in the above example.
If, however, we want to consider models of SLC over varying sets of types, then the above point of view, with its tight dependence on the initial set of types T SLC , is not adequate any more.Instead, we would like to specify the signature of SLC like this: What is the intended meaning of such a signature?For any representation T of S SLC , the variables 1 and 2 range over elements of T .In this way the number of abstractions and applications depends on the representation T of S SLC : intuitively, a model of the above signature of Eq. (3.2) over a representation T of T SLC has T 2 abstractions and T 2 applications -one for each pair of elements of T .As an example, for the final representation of S SLC in the singleton set, one obtains only one abstraction and one application morphism.In summary, to account for type variables in an arity, we consider arities of higher degree, where the degree of an arity denotes the number of (distinct) type variables.For instance, the arities abs and app of Eq. (3.2) are of degree 2.

Term Signatures, syntactically.
In this section we give a syntactic characterization of arities over a fixed algebraic signature S for types as in Def.3.1.Definition 3.9 (Type of Degree n).For n ≥ 1, we call types of S of degree n the elements of the set S(n) of types associated to the signature S with free variables in the set {1, . . ., n}.We set S(0) := Ŝ. Formally, the set S(n) may be obtained as the initial representation of the signature S enriched by n nullary arities.
Types of degree n are used to form classic arities of degree n: Definition 3.10 (Classic Arity of Degree n).A classic arity for terms over the signature S for types of degree n is of the form where t i,j , t i ∈ S(n).More formally, a classic arity of degree n over S is a pair consisting of an element t 0 ∈ S(n) and a list of pairs.where each pair itself consists of a list [t i,1 , . .

. , t i,m i ] of elements of S(n) and an element t i of S(n).
A classic arity of the form given in Eq. (3.3) denotes a constructor -or a family of constructors, for n ≥ 1 -whose output type is t 0 , and whose k inputs are terms of type t i , respectively, in each of which variables of type according to the list [t i,1 , . . ., t i,m i ] are bound by the constructor.Remark 3.11.For an arity as given in Eq. 3.3 we also write Examples of arities -besides the example of Eq. (3.2) -are also given in Sec. 4.
Remark 3.12 (Implicit Degree).Any arity of degree n ∈ N as in Def.3.10 can also be considered as an arity of degree n + 1.We denote by S(ω) the set of types associated to the type signature S with free variables in N. Then any arity of degree n ∈ N can be considered as an arity built over S(ω).Conversely, any arity built over S(ω) only contains a finite set of free variables in N, and can thus be considered to be an arity of degree n for some n ∈ N.
In particular, by suitable renaming of free variables, there is a minimal degree for any arity built over S(ω).We can thus omit the degree -e.g., the lower inner index n in Disp.3.4

B. AHRENS
-, and specify any arity as an arity over S(ω), if we really want to consider this arity to be of minimal degree.Otherwise we must specify the degree explicitly.
3.2.2.Term Signatures, semantically.We now attach a meaning to the purely syntactically defined arities of Sec.3.2.1.More precisely, we define arities as pairs of functors over suitable categories.Afterwards we restrict ourselves to a specific class of functors, yielding arities which are in one-to-one correspondence to -and thus can be compactly specified viathe syntactically defined classic arities of Sec.3.2.1.Accordingly, we call the restricted class of arities also classic arities.At first, in Rem.3.13, we present an alternative characterization of algebraic arities.This alternative point of view is then adapted to allow for the specification of arities for terms.
Remark 3.13.We reformulate the definition of algebraic arities and their representations: an algebraic arity j : n associates, to any set X, the set dom(j, X) := X n , the domain set.A representation R of this arity j in a set X then is given by a map R : X n → X.More formally, the domain set is given via a functor dom(j) : Set → Set which associates to any set X the set X n .Similarly, we might also speak of a codomain functor for any arity, which -for algebraic arities -is given by the identity functor.A representation R of j in a set X then is given by a morphism j R : dom(j)(X) → cod(j)(X) .
We take this perspective in order to define arities and signatures for terms: given an algebraic signature S for types, an arity α of degree n for terms over S is a pair of functors (dom(α), cod(α)) associating two P -modules dom(α)(P ) and cod(α)(P ), each of degree n, to any suitable monad P .A suitable monad here is a monad P on some category [T, Set] where the set T is equipped with a representation of S. We call such a monad an S-monad.A representation R of α in an S-monad P is a module morphism α R : dom(α)(P ) → cod(α)(P ) .
As we have seen in Ex. 1.1, constructors can in fact be families of constructors indexed n times by object type variables.We specify such a constructor via an arity of higher degree, where the degree n ∈ N of the arity corresponds to the number of object type variables of its associated constructor.
For any signature for types S, we define a category of monads on typed sets where the indexing set is equipped with a representation of S: Definition 3.14 (S-Monad).Given an algebraic signature S, the 2-category S-Mnd of S-monads is defined as the 2-category whose objects are pairs (T, P ) of a representation T of S and a monad P : [T, Set] → [T, Set].A morphism from (T, P ) to (T , P ) is a pair (g, f ) of a morphism of S-representations g : T → T and a monad morphism f : P → P over the retyping functor g.Transformations are the transformations of Mnd colax .
Given n ∈ N, we write S-Mnd n for the 2-category whose objects are pairs (T, P ) of a representation T of S and a monad P over [T, Set] n .A morphism from (T, P ) to (T , P ) is a pair (g, f ) of a morphism of S-representations g : T → T and a monad morphism f : P → P over the retyping functor g(n) (cf.Def.2.29).We call I S,n : S-Mnd n → Mnd colax the functor which forgets the representation of S.
We define a "large category of modules" in which modules over different S-monads are mixed together: Definition 3.15 (Large Category of Modules).Given a natural number n ∈ N, an algebraic signature S and a category D, we call LMod n (S, D) the colax comma category I S,n ↓ Id D .An object of this category is a pair (P, M ) of a monad P ∈ S-Mnd n and a P -module with codomain D. A morphism to another such (Q, N ) is a pair (f, h) of an S-monad morphism f : P → Q in S-Mnd n and a transformation h : M → f * N : Module substitution for M t is given, for f ∈ [T, C](c, Rd), by where we use that we also have f ∈ [T, C] n ((c, t), (Rd, t)) according to Def. 2.27.Going the other way round, given a family (M t ) t∈T n , we define the R n -module M by We recall that morphisms in [T, C] n are only between families with the same points t.
The remark extends to morphisms of modules; indeed, a morphism of modules α : M → N on pointed categories corresponds to a family of morphisms (α t : M t → N t ) t∈T n between the associated families of modules.
We restrict our attention to half-arities which correspond, in a sense made precise below, to the syntactically defined arities of Def.3.10.The basic brick is the tautological module of degree n: Definition 3.18.Given n ∈ N, any monad R on the category [T, Set] induces a monad R n on [T, Set] n with object map (V, t 1 , . . ., t n ) → (RV, t 1 , . . ., t n ).To any S-monad R we hence associate the tautological module of R n , Let us consider the signature S SLC of types of SLC.In the syntactically defined arities (cf.Eq. 3.2) we write terms like 1 2. We now give meaning to such a term: intuitively, the term 1 2 should associate, to a family (T, V, t 1 , t 2 ) with V a T -indexed family of sets and t 1 , t 2 ∈ T , the element t 1 t 2 .The set T should thus come equipped with a representation of S SLC in order to interpret the arrow .
More formally, such a term is interpreted by a natural transformation over a specific category, whose objects are triples of a representation T of S SLC , a family of sets indexed by (the set) T and "markers" (t 1 , t 2 ) ∈ T 2 .
We go back to considering an arbitrary signature S for types.The following are the corresponding basic categories of interest: Definition 3.19 (SSet n ).We define the category SSet n to be the category an object of which is a triple (T, V, t) where T is a representation of S, the object V ∈ [T, Set] is a T -indexed family of sets and t is a vector of elements of T of length n.We denote by SU n : SSet n → Set the functor mapping an object (T, V, t) to the underlying set T .We have a forgetful functor SSet n → T Set n which forgets the representation structure.On the other hand, any representation T of S in a set T gives rise to a functor [T, Set] n → SSet n , which "attaches" the representation structure.
The meaning of a term s ∈ S(n) as a natural transformation is now given by recursion on the structure of s: Definition 3.20 (Canonical Natural Transformation).Let s ∈ S(n) be a type of degree n.Then s denotes a natural transformation s : 1 ⇒ SU n : SSet n → Set defined recursively on the structure of s as follows: for s = α(a 1 , . . ., a k ) the image of a constructor α ∈ S we set s(T, V, t) = α(a 1 (T, V, t), . . ., a k (T, V, t)) and for s = m with 1 ≤ m ≤ n we define

s(T, V, t) = t(m) .
We call a natural transformation of the form s ∈ S(n) canonical.

Canonical natural transformations are used to build classic half-arities; they indicate context extension (derivation) and selection of specific object types (fibre):
Definition 3.21 (Classic Half-Arity over S).We give some examples of half-arities over a signature S and associate short names to them.At the same time the following clauses define an inductive set of classic half-arities, to which we will restrict our attention.
• The constant functor * : R → 1 , where 1 denotes the terminal module, is a classic half-arity.
• For any canonical natural transformation τ : 1 → T U n , the point-wise fibre module with respect to τ of the tautological module Θ n : R → • Given any (classic) half-arity M : S-Mnd → LMod n (S, Set) of degree n and a canonical natural transformation τ : 1 → T U n , the point-wise derivation of M with respect to τ is a (classic) half-arity of degree n, Here M (R) τ really means derivation of the module, i.e. derivation in the second compo- half-arities M and N of degree n, which coincide pointwise on the first component, i.e. such that M 1 = N 1 .Then their product M × N is again a (classic) half-arity of degree n.
Here the product is really the pointwise product in the second component, i.e.
Remark 3.22.Classic half-arities correspond precisely to our needs: products are needed when a constructor takes multiple arguments, and a derived module corresponds to an argument in which a variable is to be bound.The fibre restricts the terms under consideration to a specific object type.

Definition 3.23 (Weighted Set).
A weighted set J is a set J together with a map d : J → N.
An arity of degree n ∈ N for terms over an algebraic signature S is a pair of functorscalled half-arities, since two of them constitute an arity -from S-monads to modules in LMod n (S, Set).The first component dom(α) of such an arity α = (dom(α), cod(α)) denotes the domain, or arguments, of a constructor, whereas the second, cod(α), determines the output type.The degree n of an arity denotes the number of object type arguments of its associated constructor.As an example, the arities of Abs and App of Ex. 2.13 are of degree 2 (cf.Ex. 3.26).Definition 3.24 (Term-Arity, Signature over S).A classic arity α over S of degree n is a pair α = dom(α), cod(α) of half-arities over S of degree n such that • dom(α) is classic and • cod(α) is of the form [Θ n ] τ for some natural transformation τ as in Def.3.21.We write dom(α) → cod(α) for the arity α, and dom(α, R) := dom(α)(R) (and similar for the codomain functor cod).Any classic arity is thus of the form given in Eq. 3.3.Given a weighted set (J, d), a term-signature Σ over S indexed by (J, d) is a J-family Σ of classic arities over S, the arity Σ(j) being of degree d(j) for any j ∈ J. Definition 3.25 (Typed Signature).A typed signature is a pair (S, Σ) consisting of an algebraic signature S and a term-signature Σ (indexed by some weighted set) over S.

B. AHRENS
Example 3.26 (SLC, Ex. 2.13 continued).The terms of the simply typed lambda calculus over the type signature of Ex. 3.3 is given by the classic (cf.Def.3.21) arities abs : both of which are of degree 2 -we use the convention of 3.12.The outer lower index and the exponent are to be interpreted as variables, ranging over object types.They indicate the fibre (cf.Def.2.37) and derivation (cf.Def.2.34), respectively, in the special case where the corresponding natural transformation is given by a natural number as in Def.3.20.
Those two arities can in fact be considered over any algebraic signature S with an arrow constructor, in particular over the signature S PCF (cf.Ex. 3.28).
Remark 3.27.Note that in Ex. 3.26 we do not need to explicitly specify an arity for the Var term constructor in order to obtain the simply-typed lambda calculus as presented in Ex. 1.1.Indeed, in our approach every model is by definition (cf.Def.3.29) equipped with a corresponding operation -the unit of the underlying monad.
Example 3.28 (Ex.3.8 continued).We continue considering PCF.The signature S PCF for its types is given in Ex. 3.4.The term-signature of PCF is given by an arity for abstraction and an arity for application, each of degree 2, an arity (of degree 1) for the fixed point operator, and one arity of degree 0 for each logic and arithmetic constant -some of which we omit: Our presentation of PCF is inspired by Hyland and Ong's [HO00], who -similarly to Plotkin [Plo77] -consider, e.g., the successor as a constant of arrow type.As an alternative, one might consider the successor as a constructor expecting a term of type ι as argument, yielding a term of type ι.For our purpose, those two points of view are equivalent.

Representations.
A representation of a typed signature (S, Σ) is a pair (U, P ) given by a representation U of the signature S in a set -also called U -and a representation P of the term-signature Σ in a monad -also called P -over the category [U, Set].Such a representation of Σ consists of a morphism in a suitable category for each arity of Σ -the analogue of the maps Z and S from the introductory example: Definition 3.29 (Representation of a Signature over S).Let (S, Σ) be a typed signature.
A representation R of (S, Σ) is given by • an S-monad P and • for each arity α of Σ, a morphism (in the large category of modules) α R : dom(α, P ) → cod(α, P ) , such that π 1 (α R ) = id P .In the following we also write R for the S-monad underlying the representation R.
Suppose we have two such representations P and R of (S, Σ).What is a suitable definition of morphism from the first to the latter?Such a morphism is given by a pair consisting of a morphism of the underlying type representations g : S P → S R , and a monad morphism over the retyping functor associated to (the carrier of) g between the monads underlying P and R. In this way the monad morphism maps elements "of type" t ∈ S P to elements "of type" g(t) ∈ S R , and is thus compatible with the translation g of types.Note that these definitions are already integrated into the definition of S-monads.The missing piece is that the monad morphism should be compatible with the term representations of P and R: Definition 3.30 (Morphism of Representations).Given representations P and R of a typed signature (S, Σ), a morphism of representations f : P → R is given by a morphism of S-monads f : P → R, such that for any arity α of S the following diagram of module morphisms commutes: Remark 3.31.Taking a 2-categoric perspective, the above diagram reads as an equality of 2-cells P dom(α,P ) where we write df and cf instead of dom(α, f ) and cod(α, f ), respectively.The diagram of Def.3.30 lives in the category LMod n (S, Set) -where n is the degree of α -where objects are pairs (P, M ) of a S-monad P of S-Mnd n and a module M over P .The above 2-cells are morphisms in the category Mod(P n , Set), obtained by taking the second projection of the diagram of Def.3.30.Note that for easier reading, we leave out the projection function and thus write dom(α, R) for the R n -module of dom(α, R), i.e. for its second component, and similar elsewhere.
Representations of (S, Σ) and their morphisms form a category.Remark 3.32.We obtain Zsidó's category of representations [Zsi10,Chap. 6] by restricting ourselves to representations of (S, Σ) whose type representation is the initial one.More, precisely, a signature (S, Σ) maps to a signature, say, Z(S, Σ) over the initial set of sorts Ŝ in the sense of Zsidó [Zsi10, Chap.6], obtained by unbundling each arity of higher degree into a family of arities of degree 0. For instance, the signature of Ex. 3.26 maps to the signature App s,t : [()s t, ()s] −→ t , Abs s,t : [(s)t] −→ s t s,t∈T SLC .
Representations of this latter signature in Zsidó's sense then are in one-to-one correspondence to representations of the signature of Ex. 3.26 over the initial representation Ŝ of sorts, via the equivalence explained in Rem.3.17. 3.4.Initiality.
Theorem 3.33.For any typed signature (S, Σ), the category of representations of (S, Σ) has an initial object.
Proof.The proof consists of the following steps: (1) find the initial representation Ŝ of the type signature S; (2) define the monad STS of terms specified by Σ on the category [ Ŝ, Set]; (3) equip the S-monad STS with a representation structure of Σ, yielding a representation Σ of (S, Σ); (4) for any representation R of (S, Σ), give a morphism of representations i R : Σ → R; (5) prove unicity of i R .We go through these points: (1) We have already established (cf.Lem.3.7) that there is an initial representation of sorts, which we call Ŝ.Its underlying set is called Ŝ as well.
(2) The term monad we associate to (S, Σ) is the same as Zsidó's [Zsi10, Chap.6] in the sense of Rem.3.32, i.e. it is the term monad associated to Z(S, Σ).The construction of this monad in a set-theoretic setting is described in Zsidó's thesis.We will give its definition in a type-theoretic setting.
In the following the natural transformations τ i are in fact vectors of multiple transformations like those in Rem.2.31 (see also Def. 2.34), iterated by successive composition.Furthermore we make use of the simplified notation as introduced in Not.2.32.
We construct the monad which underlies the initial representation of (S, Σ), It associates to any set family of variables V ∈ [ Ŝ, Set] an inductive set of terms with the following constructors: • for every classic arity (of degree n) we have a family of constructors indexed n times by t = (t 1 , . . ., t n ) as well as by the context V ∈ [ Ŝ, Set]: • a family of constructors Var(V ) t : V t → STS(V ) t indexed by contexts and the set Ŝ of sorts.
The monadic structure is, accordingly, defined in the same way as in [Zsi10], by variablesas-terms -using the constructor Var -and flattening.
(3) The representation structure on the monad STS is defined by currying, and corresponds to Zsidó's: given an arity α of degree n in Σ, we must specify a module morphism where dom(α, STS) and dom(α, STS) are modules in Mod(STS n , Set).We define that is, the image under the constructor α from the definition of the monad STS.This yields a morphism of modules α of degree n; note that according to Rem. 3.17 it would be equivalent to specify a family α Σ t of module morphisms of suitable type, indexed by t, which is actually done by Zsidó.
(4) Given any other representation R over a set of sorts T , initiality of Ŝ gives a "translation of sorts" g : Ŝ → T .The morphism i : STS → R on terms is defined by structural recursion.Unfolding the definition of colax monad morphism, we need to define, for any context V ∈ [ Ŝ, Set], a map of type i V : ∀ t ∈ T, g(STS(V )) t → R( gV ) t .Via the adjunction of Rem.2.12 we equivalently define a map i as a family Let a ∈ STS(V ) t be a term.In case a = Var(V ) t (v) is the image of a variable v ∈ V t , we map it to i V (Var(V ) t (v)) := η R ( gV )(g(t))(ctype(v)) .Otherwise the term a = α t (V )(a 1 , . . ., a k ) ∈ STS(V ) σ(V,t) is mapped to This map is well-typed: note that g(n)(V, t) = ( gV, g * (t)) by definition (Def.2.29) and g(n)((V, t) τ ) = ( gV, g * (t)) τ , i.e. context extension and retyping permute.The axioms of monad morphisms, i.e. compatibility of this map with respect to variables-as-terms and flattening are easily checked: the former is a direct consequence of the definition of i on variables, and the latter is proved by structural induction.This definition yields a morphism of representations; consider the arity α of Σ.For this arity, the commutative diagram of Def.3.30 informally reads as follows: one starts in the upper-left corner with a tuple of terms, say, (a 1 , . . ., a k ) of STS.Taking the upper-right path corresponds to the translation of the image of this tuple under the map α Σ, i.e. under the constructor α of STS.The lower-left path corresponds to the image under the module morphism α R of the translated tuple (i(a 1 ), . . ., i(a k )).The diagram thus precisely states the equality of Eq. (3.6).We thus establish that i is (the carrier of) a morphism of representations (g, i) : ( Ŝ, Σ) → R.
(5) Unicity of the morphism i : ( Ŝ, Σ) → R is proved making use of the commutative diagram of Def.3.30.Suppose that (g , i ) : ( Ŝ, Σ) → R is a morphism of representations.We already know that g = g by initiality of Ŝ.By structural induction on the terms of

B. AHRENS
STS we prove that i = i : using the same notation as above, for a = α t (V )(a 1 , . . ., a k ) we have In case a = Var(v) is a variable, considered as a term, the fact that both i and i are monad morphisms ensures that i(Var(v)) = i (Var(v)) = η R gV (ctype(v)).Thus we have proved i = i .An application of this theorem is the specification of translations from one language ( Ŝ, Σ) -associated to a typed signature (S, Σ) -to another ( Ŝ , Σ ).We place ourselves in the category of representations of (S, Σ).In order to obtain said translation as an initial morphism in this category, it suffices to equip ( Ŝ , Σ ) with a representation of (S, Σ).Doing so consists in, firstly, representing S in the set Ŝ , yielding a translation of types Ŝ → Ŝ .Afterwards the translation of terms is given, via a similar iteration principle as for types, by representing the signature Σ in Σ .
We illustrate this iteration principle using two examples: firstly, in Sec. 4 we specify a translation of logics from classical logic to intuitionistic logic.Secondly, we specify translations from PCF to the untyped lambda calculus via initiality.The latter example is implemented in the proof assistant Coq, cf.Sec. 5.

Logics and Logic Translations
In the style of the Curry-Howard isomorphism, we consider propositions as types and proofs of a proposition as terms of that type.In this example we present the typed signatures of two different logics, • Classical propositional logic, called CPC, and • Intuitionistic propositional logic, called IPC.According to our main theorem each of those signatures gives rise to an initial representation, a logical type system.We then use the iteration principle on CPC in order to specify a translation of propositions and their proofs from CPC to IPC.The translation we specify is actually the propositional fragment of the Gödel-Gentzen negative translation [TvD88,Def. 3.4].
where for any atomic formula p ∈ P we have an arity p : 0. We call P the initial representation as well as its underlying set, i.e. the propositions of CPC and IPC.For the set P we use infixed binary constructors.Note that negation is defined as ¬A ≡ A ⇒ ⊥.

Inference Rule Arity
Table 1: Inference Rules of CPC and their Arities 4.1.1.Signature of CPC.Concerning the terms of CPC, every inference rule is given by an arity.In Table 1, the inference rules and their corresponding arities are presented.Each inference rule corresponds to a (family of) term -proof -constructor(s), where inference rules without hypotheses are constants.Note that the initial representation automatically comes with an additional inference rule var Γ, A A corresponding to the monadic operation η, i.e. to the variables-as-terms constructor.Analogously to Rem. 3.27, it is not necessary, using our approach, to specify this inference rule explicitly by an arity in the term signature of the logic under consideration; any logic we specify via a typed signature automatically comes with this rule.4.1.2.Signature of IPC.The type signature and thus the formulas of intuitionistic propositional logic IPC are the same as for CPC.However, the term signature is missing the arity EM for excluded middle.

Translation via Initiality.
The translation of propositions (_) g : P → P, i.e. on the type level, is specified by a representation g of the algebraic signature P in the set P. According to Def. 3.2 we must specify, for any arity s : n ∈ N of P, a map towards P taking a suitable number of arguments in P, s g : Pn → P .
There is, of course, a canonical such map for each arity -but this would only give us the identity morphism on P. We represent P in P not by this identity representation, but in such a way that we obtain the Gödel-Gentzen negative translation: The proofs of IPC are given by the signature of CPC without the classical axiom EM.We represent EM in IPC by giving, for any proposition A, a term of type ¬(¬¬A ∧ ¬A), e.g., As another example, we give a representation of ∨ I1 , that is, for any proposition A and B, we give a term of type A g → ¬(¬A g ∧ ¬B g ): De Morgan ¬(¬A g ∧ ¬B g ) Here the proof of A g → ¬¬A g and of the used De Morgan law are abbreviations for longer proofs in IPC.We leave it up to the reader to find representations in IPC for the other arities.4.3.Some Remarks.This representation of the signature of CPC in IPC yields the (propositional fragment of the) Gödel-Gentzen translation of propositions specified in Troelstra and van Dalen's book [TvD88, Def.3.4], denoted on propositions with the same name as its specifying representation, (_) g : P → P .
Note that our translation of terms shows that any provable proposition in CPC translates to a provable proposition in IPC, since we provide the corresponding proof term via our translation: Γ C A implies Γ g I A g .However, a logic translation t from a logic L to another logic L should certainly satisfy an equivalence of the form Γ L A if and only if Γ t L A t .Our framework does not ensure the implication from right to left, and is thus deficient from the point of view of logic translations.

Translation of PCF to ULC, Formalized
In this section we explain our formalization in the proof assistant Coq of an instance of our main theorem (cf.Thm.3.33), for the typed signature of PCF (cf.Exs.3.4, 3.8, 3.28).For this, we make several simplifications: • we do not define a notion of 2-signature, but specify directly a Coq type of representations of PCF and • we use dependent Coq types to formalize arities of higher degree (cf.Def.3.16), instead of relying on modules on pointed categories.A representation of an arity of degree n is thus given by a family of module morphisms, indexed n times over the respective object type (cf.Rem.3.17).The formalization builds up on a library of category theory the details of which we will not go into.We just note that Coq types play the role of sets in our formalization.Maps of sets are hence modelled by Coq functions and thus executable.In particular, the initial morphism is a Coq function, and we can compute the translation of a term of PCF inside Coq.For now we just give some key definitions of the theory-specific part.For complete description we refer to the online documentation and source code repository2 .As a side note, the theorem relies on the axioms eq_rect_eq and functional_extensionality_dep from the Coq standard library.
In the following we write Coq code in sans serif font.For a morphism f from object a to object b in any category we write f : a −−−> b in Coq.Composition of morphisms f : a → b and g : b → c is written f ;; g.

The Category of Representations.
A representation of the typed signature of PCF is given by (1) a representation of the types of PCF (in a Coq type Sorts), cf.Ex. 3.4, (2) a monad P on the category of families of sets indexed by Sorts (in the formalization: ITYPE Sorts) and (3) representations of the arities of PCF (cf.Ex. 3.28), i.e. morphisms of P -modules with suitable source and target modules.We implement representations of PCF as a "bundle", i.e. a record type, whose componentsor "fields" -are these 3 items.In order to make the definitions more traceable, we first define what a representation of the term signature of PCF in a monad P is, in the presence of an S PCF -monad (cf.Def.3.14).Unfolding the definitions, we suppose given a type Sorts, a monad P on ITYPE Sorts and three operations on Sorts: a binary function Arrow -denoted by an infixed "~~>" -and two constants Bool and Nat.
In this context, a representation of PCF is given by a bunch of module morphisms.Note that M[t] denotes the fibre module of module M w.r.t.t, and d M // u denotes derivation of Here the morphism Succ refers to the representation of the successor arity either of P (the first appearance) or R (the second appearance) -Coq is able to figure this out itself.The morphism f * * Succ thus is the pullback along f of the module morphism Succ of the representation R -recall that pullback is functorial.The domain of the successor is given by the terminal module * .Accordingly, we have that dom(Succ, f ) is the trivial module morphism with domain and codomain given by the terminal module.We denote this module morphism by * −−−> * .The codomain is given as the fibre of f of type ι → ι.The two remaining module morphisms are isomorphisms which do not appear in the informal description.The isomorphism IsoPF is needed to permute fibre with pullback -in the formalization the 2-category of monads behaves like a bicategory, since composition is associative up to isomorphism only, due to Coq conversion being stronger than propositional equality.The morphism Fib_eq_Mod M H takes a module M and a proof H of equality of two object types as arguments, say, H : u = v.Its output is an isomorphism M Here the proof is of type H : Sorts_map (Nat ~~> Nat) = Sorts_map Nat ~~> Sorts_map Nat and Coq is able to figure the proof, i.e. the term, out itself.
Finally, we prove that the objects and morphisms thus defined yield a category, where the composition and identity are given by composition and identity of monad morphisms, respectively.We omit the description of this part of the formalization.5.2.The Initial Representation.We want to prove that the above specified category admits an initial object, consisting of the term monad associated to the signature of PCF, together with the canonical representation morphisms.The monad of PCF terms is defined as an inductive dependent type, parametrized by the initial set of types of PCF, denoted by TY, as well as a context V. First we define the constants of PCF, afterwards the inductive type family of terms: Renaming, i.e. functoriality, and substitution, are then defined via structural recursion, and the monad laws are proved by induction, accordingly.We refer to the source code or documentation for details.Given any representation R of PCF, the initial morphism is iteratively defined according to the proof of the main theorem: Again, the necessary properties, i.e. the monad morphism laws, representation laws, and finally, unicity, are proved by induction.Note that the above family of maps init V really is the family of the adjuncts of the initial morphism under the adjunction of Rem.2.12, cf. also the proof of Thm.3.33.The component on V of the initial morphism is obtained by precomposing the map init V with pattern matching on the constructor ctype.= Abs (Abs (1 @ (2 @ 2 @ 1))) @ Abs (Abs (1 @ (2 @ 2 @ 1))) Eval compute in ULC_Y.

Future Work
We have given an algebraic interpretation of maps between languages over different sets of types.Our initiality theorem yields a iteration operator that allows for the specification of such translations.
Another line of work of ours is to integrate semantics into initiality results [Ahr11].We study untyped syntax equipped with reduction rules by considering it as a relative monad [ACU10] (over the diagonal functor ∆ : Set → Ord) from the category of sets to the category of preorders Ord.A 2-signature consists of a syntactic signature Σ which defines the terms of a language, as well as of a set A of inequations, each of which specifies a reduction rule.Representations of such a 2-signature (Σ, A) are representations of Σ which verify each inequation α ∈ A. We prove that the category of representations of (Σ, A) has an initial object.
The present work carries over to relative monads, and we can thus study translations of languages over different types which are equipped with reduction rules.In a forthcoming work we will prove an initiality theorem for simply-typed syntax with reduction rules, and we will present a translation via initiality from PCF, equipped with its usual reduction rules, to ULC with beta reduction.The translation is ensured to be semantically faithful.

Remark 2. 3 (
Kleisli Operation (Monadic Bind)).Given a monad (T, η, µ) on the category C, the Kleisli operation with type (_) * a,b : C(a, T b) → C(T a, T b) is defined, for any a, b ∈ C and f ∈ C(a, T b), by setting (f ) * the category C. Put differently, every map g : T → T induces an endofunctor ḡ on [T, C] with object map ḡ(V ) := g(V ) • g and we have a natural transformation ctype : Id ⇒ ḡ : [T, C] → [T, C] .
The notion of module over a monad generalizes monadic substitution (cf.[HM07]):Definition 2.15 (Module over a Monad).Given a monad T over category C and a category D, a module over T with codomain D (or T -module towards D) is a colax monad morphism (M, γ) : (C, T ) → (D, Id D ) from T to the identity monad on D. Given T -modules M and N , a morphism of modules from M to N is a transformation from M to N .We call Mod(T, D) := Mnd colax (C, T ), (D, Id) the category of T -modules towards D. Remark 2.16.By unfolding the preceding definition and simplifying, we obtain that a T -module towards D is a functor M : C → D together with a natural transformation σ : M T → M such that the following diagrams commute: Definition 2.22 (Tautological Module).Given the monad (C, T ), we call tautological module the module (T, µ T ) : (C, T ) → (C, Id).Definition 2.23 (Constant and terminal module).Given a monad (C, T ) and a category D with an object d ∈ D, the constant functor F d : C → D mapping any object of C to d ∈ D and any morphism to the identity on d yields a module (F d , id) : (C, T ) → (D, Id) .In particular, if D has a terminal object 1 D , then the constant module (F 1 D , id) is terminal in Mod(T, D).Given a morphism of monads from T to T , and T -module gives rise to a T -module: Definition 2.24 (Pullback module).Let (C, T ) and (D, T ) be monads over C and D, respectively.Given a morphism of monads (F, γ) : (C, T ) → (D, T ) and a T -module (M, σ) with codomain category E, we call pullback of M along (F, γ) the composed T -module
Definition 3.16 (Half-Arity over S (of degree n)).Given an algebraic signature S and n ∈ N, we call half-arity over S of degree n a functor α : S-Mnd → LMod n (S, Set) .Taking into account Rem.3.17, this means a half-arity of degree n associates to any S-monad R -with representation of S in a set T -a family of R-modules indexed n times by T .Remark 3.17 (Module on pointed Category ∼ = Family of Modules).Let C and D be categories, let T be a set and R be a monad on [T, C].Suppose n ∈ N, and let D be a category.Then modules over R n with codomain D correspond precisely to families of R-modules indexed by T n with codomain D by (un)currying.More precisely, let M be an R n -module.Given t ∈ T n , we define an R-module M t by M t (c) := M (c, t) .
This construction extends to a functor.

5. 3 .
Representing PCF in the Untyped Lambda Calculus.The untyped lambda calculus, formalized as a monad ULC : Set → Set, gives rise to a monad uULC : [{ * }, Set] → [{ * }, Set], in which we represent PCF.Our implementation does not allow us to identify those two monads, but we do so informally.By its iterative definition, the initial morphism depends on the representation in the codomain monad.Giving two different representations of PCF in ULC gives rise to two different translations of PCF to ULC.As an example, one might choose to use different representations of natural numbers or the fixed point operator.This is simply done by defining two different ULC terms as image of the fixed point operator rec.We define the Turing fixed point combinator Θ := (λx.λy.(y(xxy)))(λx.λy.(y(xxy))) and the Curry combinator Y := λf.(λx.f(xx))(λx.f(xx)) formally:Eval compute in ULC_theta.
When considering constructors that are indexed by object types, such as App and Abs, we will also consider monads and modules over categories of typed sets where the set of types is pointed (multiple times): Definition 2.27 (Pointed index sets).Given a category C, a set T and a natural number n, we denote by [T, C] n the category with, as objects, diagrams of the form n B. AHRENSDefinition 2.26 (Products).Suppose the category D is equipped with a product.Given any monad (C, T ), the product of D lifts to a product on the category Mod(T, D) of T -modules with codomain D.2.3.Modules on Typed Sets.t → T V → C ,written (V, t 1 , . . ., t n ) with t i := t(i).A morphism h to another such (W, t) with the same pointing map t is given by a morphism h :