The clocks they are adjunctions:Denotational semantics for Clocked Type Theory

04/18/2018 ∙ by Bassel Mannaa, et al. ∙ 0

Clocked Type Theory (CloTT) is a type theory for guarded recursion useful for programming with coinductive types, allowing productivity to be encoded in types, and for reasoning about advanced programming language features using an abstract form of step-indexing. CloTT has previously been shown to enjoy a number of syntactic properties including strong normalisation, canonicity and decidability of type checking. In this paper we present a denotational semantics for CloTT useful, e.g., for studying future extensions of CloTT with constructions such as path types. The main challenge for constructing this model is to model the notion of ticks used in CloTT for coinductive reasoning about coinductive types. We build on a category previously used to model guarded recursion, but in this category there is no object of ticks, so tick-assumptions in a context can not be modelled using standard tools. Instead we show how ticks can be modelled using adjoint functors, and how to model the tick constant using a semantic substitution.



There are no comments yet.


page 1

page 2

page 3

page 4

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

In recent years a number of extensions of Martin-Löf type theory [14] have been proposed to enhance the expressiveness or usability of the type theory. The most famous of these is Homotopy Type Theory [18], but other directions include the related Cubical Type Theory [11], FreshMLTT [17], a type theory with name abstraction based on nominal sets, and Type Theory in Color [4] for internalising relational parametricity in type theory. Many of these extensions use denotational semantics to argue for consistency and to inspire constructions in the language.

This paper is part of a project to extend type theory with guarded recursion [16], a variant of recursion that uses a modal type operator (pronounced ‘later’) to preserve consistency of the logical reading of type theory. The type

should be read as classifying data of type

available one time step from now, and comes with a map and a fixed point operator mapping a function to a fixed point for . This, in combination with guarded recursive types, i.e., types where the recursive variable is guarded by a , e.g., gives a powerful type theory in which operational models of combinations of advanced programming language features such as higher-order store [7] and nondeterminism [8] can be modelled using an abstract form of step-indexing [1]. Combining this with a notion of clocks, indexing the operator with clock names, and universal quantification over clocks, one can encode coinduction using guarded recursion, allowing productivity [12] of coinductive definitions to be encoded in types [2].

The most recent type theory with guarded recursion is Clocked Type Theory (CloTT[3], which introduces the notion of ticks on a clock. Ticks are evidence that time has passed and can be used to unpack elements of type to elements of . In fact, in CloTT, is a special form of function type from ticks to . The combination of ticks and clocks in CloTT can be used for coinductive reasoning about coinductive types, by encoding the delayed substitutions of [9].

Bahr et al [3] have shown that CloTT can be given a reduction semantics satisfying strong normalisation, confluence and canonicity. This establishes that productivity can indeed be encoded in types: For a closed term of stream type, the ’th element can be computed in finite time. These syntactic results also imply soundness of the type theory. However, these results have only been established for a core type theory without, e.g., identity types, and the arguments can be difficult to extend to larger calculi. In particular, we are interested in extending CloTT with path types as in Guarded Cubical Type Theory [5]. Therefore a denotational model of CloTT can be useful, and this paper presents such a model.

The work presented here builds on a number of existing models for guarded recursion. The most basic such, modelling the single clock case, is the topos of trees model [7], in which a closed type is modelled as a family of sets indexed by natural numbers , together with restriction maps of the form for every . In other words, a type is a presheaf over the ordered natural numbers. In this model is modelled as and and guarded recursion reduces to natural number recursion. The guarded recursive type mentioned above can be modelled in the topos of trees as .

Bizjak and Møgelberg [10] recently extended this model to the case of many clocks, using a category of covariant presheaves over a category of time objects, i.e., pairs of a finite set and a map . In this model, universal quantification over clocks is modelled by constructing an object in the topos of trees and taking the limit of that. For example, taking the limits over the object gives the usual coinductive type of streams over natural numbers.

The main challenge when adapting the model of [10] to CloTT is to model ticks, which were not present in the language modelled in [10]. In particular, how does one model tick assumptions of the form in a context, when there appears to be no object of ticks in the model to be used as the denotation of the clock . In this paper we observe that these assumptions can be modelled using a left adjoint to the functor used in [10] to model the delay modality associated to the clock . Precisely we model context extension as . To clarify what is needed to model ticks, we focus on a fragment of CloTT called the tick calculus capturing just the interaction of ticks with dependent types. We show that the tick calculus can be modelled soundly in a category with family [13] (a standard notion of model for dependent type theory), with an adjunction of endofunctors on the underlying category, for which the right adjoint lifts to types and terms, and there is a natural transformation from to the identity. This appears to be a general pattern seen also in the model of fresh name abstraction of FreshMLTT [PITTS201519] and dependent path types in cubical type theory [11]. Similarly challenging is how to model the special tick constant . Since there is no object of ticks, there is no element corresponding to either. Still, we shall see that there exists a semantic substitution of for a tick variable that can be used to model application of terms to .

The paper is organised as follows: The tick calculus and its model theory are introduced in Section 2. Section 3 introduces CloTT, omitting guarded recursive types and universes, which we leave for future work. Section 4 presents the basics of the model, in particular the presheaf category and the adjunction . The presence of ticks in contexts leads to a non-standard notion of substitutions, and we study the syntax and semantics of these in Section 5. Sections 6 and 7 extend the model with universal quantification over clocks and , respectively. Finally, Section 8 verifies the important clock irrelevance axiom, and Section 9 concludes and discusses future work.

2 A tick calculus

Before introducing CloTT we focus on a fragment to explain the notion of ticks and how to model these. To motivate ticks, consider the notion of applicative functor from functional programming [15]: a type former with maps and satisfying a number of equations that we shall not recall. These maps can be used for programming with the constructor , but for reasoning in a dependent type theory, one needs an extension of these to dependent function types. For example, in guarded recursion one can prove a theorem by constructing a map and taking its fixed point in . If the theorem is that a property holds for all elements in a type of guarded streams satisfying , then will be of the form . To apply the (essentially coinductive) assumption of type to the tail of a stream, which has type we need an extension of the applicative functor action.

What should the type of such an extension be? Given and the application of to should be something of the form . If we think of as a delay, intuitively is a value of type delayed by one time, and the should be the value delivered by one time step from now. Ticks are evidence that time has passed, and they allow us to talk about values delivered in the future.

The tick calculus is the extension of dependent type theory with the following four rules

An assumption of the form in a context is an assumption that one time step has passed, and is the evidence of this. Variables on the right-hand side of such an assumption should be thought of as arriving one time step later than those on the left. Ticks can be abstracted in terms and types, so that the type constructor now comes with evidence that time has passed that can be used in its scope. The type can be thought of as a form of dependent function type over ticks, which we abbreviate to if does not occur free in . The elimination rule states that if a term can be typed as before the arrival of tick , can be opened using to give something of type . Note that the causality restriction in the typing rule prevents a term like being well typed; a tick can only be used to unpack the same term once. The context in the elimination rule ensures that typing rules are closed under weakening, also for ticks. Note that the clock object is not a type.

The equality theory is likewise extended with the usual and rules:

As stated, the tick calculus should be understood as an extension of standard dependent type theory. In particular one can add dependent sums and function types with standard rules. Variables can be introduced from anywhere in the context, also past ticks.

We can now type the dependent applicative structure as

For a small example on how ticks in combination with the fixed point operator can be used to reason about guarded recursive data, let be the type of guarded recursive streams mentioned above, and suppose is a family to be thought of as a predicate on (where is the pairing of and ). A lifting of to streams would be another guarded recursive type satisfying . If is a proof of we would expect that also can be proved, and indeed this can be done as follows. Consider first

Then has the desired type.

More generally, ticks can be used to encode [3] the delayed substitutions of [9], which have been used to reason coinductively about coinductive data. For more examples of reasoning using these see [9]. For reasons of space, we will not model general guarded recursive types in this paper, but see Section 4 for how to model the types used above.

2.1 Modelling ticks using adjunctions

We now describe a notion of model for the tick calculus. It is based on the notion of category with families (CwF) [13], which is a standard notion of model of dependent type theory. Recall that a CwF is a pair such that is a category with a distinguished terminal object and is a functor together with a comprehension map to be recalled below. The functor associates to every object in a map and to every morphism maps and such that . Following standard conventions, we write to mean and to mean , and we write for when , and likewise for when . We refer to the objects of as contexts, morphisms as substitutions, elements of as types and elements of as terms.

Comprehension associates to each a context , a substitution and a term , such that for every , and there exists a unique substitution such that and .

To model the tick calculus we need an operation modelling the extension of a context with a tick, plus an operation modelling . In the simply typed setting, would be a right adjoint to context extension, but for dependent types this is not quite so, since these operations work on different objects (contexts and types respectively). In the model we consider in this paper, the right adjoint does exist as an operation on contexts, but also extends to types and terms in the sense of the following definition. Let be a CwF and let be a functor. An extension of to types and terms is a pair of operations on types and term presented here in the form of rules

commuting with substitutions in the sense that and hold for all substitutions , and commuting with comprehension in the sense that there exists an operation associating to each a morphism in inverse to . A CwF with adjunction is a pair of adjoint endofunctors with an extension of to types and terms.

Given a CwF with adjunction, one can define an operation mapping types to types defined as where is the unit of the adjunction.

There is a bijective correspondence between terms and terms for which we write for both directions where is given by and is given by . Moreover, if , and then

2.2 Interpretation

The notion of CwF with adjunction is almost sufficient for modelling the tick calculus, but to interpret tick weakening, we will assume given a natural transformation . Defining

allows us to define a context projection by induction on using in the case of tick variables. We can then define the rest of the interpretation as

Proposition .

The above interpretation of the tick calculus into a CwF with adjunction and tick weakening is sound.

3 Clocked Type Theory

Clocked Type Theory (CloTT) is an extension of the tick calculus with guarded recursion and multiple clocks. Rather than having a global notion of time as in the tick calculus, ticks are associated with clocks and clocks can be assumed and universally quantified. Judgements have a separate context of clock variables , for example, the typing judgement has the form , where is a set of clock variables . The clock context can be thought of as a context of assumptions of the form that appear to the left of the assumptions of , except that is not a type. There are no operations for forming clocks, only clock variables. It is often convenient to have a single clock constant and this can be added by working in a context of a single clock variable.

Type formation rules *

κ∈Δ *

Γ ⊢_Δ Typing rules * Γ ⊢_Δ, κ t: A

Γ ⊢_Δ Γ ⊢_Δ Λκ. t: ∀κ. A * Γ ⊢_Δ t: ∀κ. A

κ’∈Δ Γ ⊢_Δ t [κ’]: A [κ’/κ] * Γ,α:κ ⊢_Δ t: A

κ∈Δ Γ ⊢_Δ λ(α : κ). t: ▷  (α:κ) . A * Γ ⊢_Δ t: ▷  (α:κ) . A

Γ,α’:κ,Γ’ ⊢_Δ Γ,α’: κ,Γ’ ⊢_Δ t [α’] : A[α’/α] * Γ ⊢_Δ,κ t: ▷  (α:κ) . A

Γ ⊢_Δ

κ’∈Δ Γ ⊢_Δ (t [κ’/κ]) [⋄] : A[κ’/κ][⋄/α] * Γ ⊢_Δ t: ▷^κA →A Γ ⊢_Δ dfix^κ t: ▷^κA Judgemental equality

Figure 1: Selected typing and judgemental equality rules of Clocked Type Theory.

The rules for typing judgements and judgemental equality are given in Figure 1. These should be seen as an extension of a dependent type theory with dependent function and sum types, as well as extensional identity types. The rules for these are completely standard (ignoring the clock context), and thus are omitted from the figure. We write for judgemental equality and for identity types. The model will also model the identity reflection rule

of extensional type theory.

The guarded fixed point operator is useful in combination with guarded recursive types. Suppose for example that we have a type of natural numbers and a type of guarded recursive streams satisfying . One can then use for recursive programming with guarded streams, e.g., when defining a constant stream of zeros as . The type of ensures that only productive recursive definitions are typeable, e.g., is not.

The tick constant gives a way to execute a delayed computation of type to compute a value of type . In particular, if is a fixed point, application to the tick constant unfolds the fixed point once. This explains the need to name ticks in CloTT: substitution of for a tick variable in a term allows for all fixed points applied to in the term to be unfolded. In particular, the names of ticks are crucial for the strong normalisation result for CloTT in [3].

To ensure productivity, application of must be restricted. In particular a term such as should not be well typed. The typing rule for application to the tick constant ensures this by assuming that the clock associated to the delay is not free in the context of the term . For example, the rule

is admissible, which can be proved using weakening lemma for the clock variable context. This rule, however, is not closed under variable substitution, which is the motivation for the more general rule of Figure 1. The typing rule is a bit unusual, in that it involves substitution in the term in the conclusion. We shall see in Section 7.1 that this causes extra proof obligations for welldefinedness of the denotational semantics.

Universal quantification over clocks allow for coinductive types to be encoded using guarded recursive types [2]. For example is a coinductive type of streams. The head and tail maps and can be defined as

using the clock constant .

Finally we recall the clock irrelevance axiom


crucial for correctness of the encoding of coinductive types [2]. Note that the hypothesis implies that is not free in . This rule can be used to prove that is isomorphic to if is not free in . Likewise the tick irrelevance axiom


states that the identity of ticks is irrelevant for the equality theory, despite being crucial for the reduction semantics. Tick irrelevance implies fixed point unfolding

The type theory CloTT as defined in [3] also has guarded recursive types and a universe. We leave these for future work, see Section 9.

4 Presheaf semantics

The setting for the denotational semantics of CloTT is a category of covariant presheaves over a category of time objects. This category has previously been used to give a model of GDTT [10].

We will assume given a countably infinite set of (semantic) clock variables, for which we use to range over. A time object is a pair where is a finite subset of and is a map giving the number of ticks left on each clock in . We will write the finite sets as lists writing e.g., for and for the extension of to , or indeed for the update of , if is already defined on . A morphism is a function such that in the pointwise order. The inequality allows for time to pass in a morphism, but morphisms can also synchronise clocks in by mapping them to the same clock in , or introduce new clocks if is not surjective. Define to be the category of covariant presheaves on . The topos of trees can be seen as a restriction of this where time objects always have a single clock.

The category contains a special object of clocks, given by the first projection . If is a set, one can form the object as . Let be the category of elements of , i.e., the objects are triples where and and a morphism is a morphism such that . A clock context will be interpreted as and contexts, types and terms in clock context will be modelled in the category of covariant presheaves over . If is a covariant presheaf over and and we will write for .

To describe the model of CloTT, we start by fixing a clock context and modelling the fragment of CloTT excluding universal quantification over clocks and the tick constant . The resulting fragment is a version of the tick calculus with one notion of tick for each clock in . To model this, we need the structure of a CwF with adjunction on for each in . Recall that, like any presheaf category, can be equipped with the structure of a CwF where contexts are objects, types in context are presheaves over the elements of and terms are sections. Precisely, a type over is a mapping associating a set to each and to each a mapping such that and for all and . A term is a mapping associating to each an element such that . We often make the underlying object explicit writing .

As an example of a model of a type, recall the type of guarded streams satisfying from Section 3. This is a closed type in a clock context (assuming ), and so will be interpreted as a presheaf in defined as . We will assume that the products in this associate to the right, so that this is the type of tuples of the form . This is needed to model the equality , rather than just an isomorphism of types. Given a predicate , we can lift it to a predicate satisfying as in Section 2, by defining

It is a simple calculation (using the definitions below) that these interpretations model the type equalities mentioned above.

4.1 Adjunction structure on

For the adjunction, recall that in the topos of trees the functor is defined as and . This has a left adjoint defined as . The right adjoint generalises in a straight forward way to the multiclock setting of CloTT: If is in , define

where and for . This is the same definition as used in the GDTT model of [10].

The functor extends to types and terms.


We just give the definitions. For define

The case for terms is similar.

The isomorphism is given by

At first sight it would seem that one can define a left adjoint to the above functor given by , where is defined similarly to . Unfortunately, so described is not a presheaf because it has no well-defined action on maps since a map does not necessarily induce a map : If there is no guarantee that .

To get the correct description of the left adjoint consider the set of syntactic clocks synchronised with by . Given a morphism , more clocks can be synchronised with by than , but never fewer. If we think of time as flowing in the direction of morphisms, the left adjoint must take into account all the possible ways that could have been synchronised with fewer syntactic clocks “in the past”. Such a past is given by a subset such that .

The functor has a left adjoint given by

where for a chosen clock name fresh for .

Finally, the projection maps an element in to where

is defined as and for . Collectively, Lemmas 4.1 and 4.1 together with the projection state that for each , carries the structure of a model of the tick calculus. This is enough to model the tick abstractions and applications of CloTT.

The adjoint correspondent to maps an element to its restriction in . This is the map referred to as in [10]. Moreover, a simple calculation shows that the interpretation of , i.e., for not free in , is the same as in [10], namely

We can thus define the interpretation of as in [10] by induction on :

Finally we note soundness of the tick irrelevance axiom (2).

Proposition .

If then

5 Substitutions

Having described the interpretation of the fragment of CloTT that lives within a fixed clock context it remains to describe the interpretation of the universal quantification over clocks and of the tick constant . Quantification over clocks can be seen as a dependent product over a type of clocks, and should therefore be modelled as a right adjoint to weakening in the clock context. Weakening is an example of a substitution and, as we shall see, the tick constant will also be modelled using a form of substitution. We therefore first study substitutions, which are non-standard in CloTT because of the two contexts, and because of the unusual typing rules for ticks.

5.1 Syntactic substitutions

A syntactic substitution from to is a pair of a substitution of clocks for clocks and a substitution of terms for variables and ticks for ticks variables. Substitutions are formed according to the following rules.

  • If is a map of sets, then

  • If and then

  • If and and are welformed then

  • If , and , then

Here is the result of substituting along which is defined in the standard way.

5.2 Semantic substitutions

The clock substitution gives rise to a functor mapping an object to , and this induces a functor by . This functor extends to a morphism of CwFs [13], in particular it maps a type in context in the CwF structure of to a type in context the CwF structure of , and likewise for terms. For example, for is defined as . Moreover, this map commutes on the nose with comprehension and substitution. For example, if is a type in context in and , then . Moreover, it commutes with in the following sense.

If and then .

The interpretation of a substitution is a morphism

in , which we will define below. But first we state the substitution lemma, which must be proved by induction on terms and types simultaneously with the definition of the interpretation, as is standard for models of dependent type theory.

Let be a substitution and let be a judgement of a wellformed type or a typing judgement. Then .

The main difficulty for defining the interpretation of substitutions is that the operator does not commute with clock substitutions in the sense that is not necessarily equal to . However, we can define a map in the relevant direction:

where is the unit of the adjunction and

is the counit. The composition type checks since .

The map has a simple description in the model: maps an element in

to in the set which equals

The interpretation of substitutions is defined as

where we have assumed the types as in the rules for forming substitutions and is the context projection defined as in Section 2.2. The last case uses which will be defined in Section 7 below.

The rest of this section is a sketch proof of the substitution lemma for the fragment of CloTT modelled so far, i.e., excluding quantification over clocks and . As we extend the interpretation we will also extend the proof of the substitution lemma.

The proof is by induction over judgements and is simultaneous with the definition of the interpretation of substitutions. The cases of standard dependent type theory (dependent functions and sums, identity types) can be essentially reduced to the standard proof of the substitution lemma for dependent type theory in presheaf models as follows (although the non-standard notion of substitution requires some new lemmas). Since is the object of presheaves over , the category of elements of , given a context one can form the comprehension as an object of . Types and terms in context in the CwF structure associated to are then in bijective correspondence with those over in the CwF structure of . A substitution induces a morphism in and the substitution defined above corresponds to substitution along this map. Thus the interpretation of the standard type theoretic constructions are the same as the standard ones in the presheaf model , and the corresponding cases of the substitution lemma can be proved similarly to the standard proof of the substitution lemma for presheaf models of type theory.

The cases corresponding to the constructions from the tick calculus follow from the following two equations.


For example, the case of can be proved as follows (writing