<<

Multimodal Dependent

Daniel Gratzer G. A. Kavvos Aarhus University Aarhus University [email protected] [email protected] Andreas Nuyts Lars Birkedal imec-DistriNet, KU Leuven Aarhus University [email protected] [email protected] Abstract 1 Introduction We introduce MTT, a theory which sup- In order to increase the expressivity of Martin-Löf Type ports multiple modalities. MTT is parametrized by a mode Theory (MLTT) we often wish to extend it with new con- theory which specifies a collection of modes, modalities, nectives, and in particular with unary type operators that and transformations between them. We show that different we call modalities or modal operators. Some of these modal choices of mode theory allow us to use the same type theory operators arise as shorthands, while others are introduced as to compute and reason in many modal situations, includ- a device for expressing structure that appears in particular ing guarded recursion, axiomatic cohesion, and parametric models. Whereas the former class of modalities are internally quantification. We reproduce examples from prior work in definable62 [ ], the latter often require extensive modifica- guarded recursion and axiomatic cohesion — demonstrating tions to the basic structure of type-theoretic judgments. In that MTT constitutes a simple and usable syntax whose in- some cases we are even able to prove that these changes are stantiations intuitively correspond to previous handcrafted necessary, by showing that the modality in question can- modal type theories. In some cases, instantiating MTT to not be expressed internally: see e.g. the ‘no-go’ theorems a particular situation unearths a previously unknown type by Shulman [67, §4.1] and Licata et al.[42]. This paper is theory that improves upon prior systems. Finally, we inves- concerned with the development of a systematic approach tigate the metatheory of MTT. We prove the consistency to the formulation of type theories with multiple modalities. of MTT and establish canonicity through an extension of The addition of a modality to a dependent type theory is a recent type-theoretic gluing techniques. These results hold non-trivial exercise. Modal operators often interact with the irrespective of the choice of mode theory, and thus apply to context of a type or term in a complicated way, and naïve a wide variety of modal situations. approaches lead to undesirable interplay with other type formers and substitution. However, the consequent gain in CCS Concepts: • Theory of computation → Modal and expressivity is substantial, and so it is well worth the effort. temporal ; Type theory; Proof theory. For example, modalities have been used to express guarded recursive definitions [10, 15, 16, 33], parametric quantifi- Keywords: Modal types, dependent types, categorical se- cation [54, 55], proof irrelevance [3, 54, 57], and to define mantics, gluing, guarded recursion global operations which cannot be localized to an arbitrary context [42]. There has also been concerted effort towards ACM Reference Format: the development of a dependent type theory correspond- Daniel Gratzer, G. A. Kavvos, Andreas Nuyts, and Lars Birkedal. ing to Lawvere’s axiomatic cohesion [41], which has many Proceedings of the 2020. Multimodal Dependent Type Theory. In interesting applications [32, 40, 64, 65, 67]. 35th Annual ACM/IEEE Symposium on in Despite this recent flurry of developments, a unifying ac- (LICS ’20), July 8–11, 2020, Saarbrücken, Germany. ACM, New York, NY, USA, 15 pages. https://doi.org/10.1145/3373718.3394736 count of modal dependent type theory has yet to emerge. Faced with a new modal situation, a type theorist must hand- craft a brand new system, and then prove the usual battery of metatheorems. This introduces formidable difficulties on Permission to make digital or hard copies of part or all of this work for two levels. First, an increasing number of these applications personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies are multimodal: they involve multiple interacting modalities, bear this notice and the full citation on the first page. Copyrights for third- which significantly complicates the design of the appropri- party components of this work must be honored. For all other uses, contact ate judgmental structure. Second, the technical development the owner/author(s). of each such system is entirely separate, so that one can- LICS ’20, July 8–11, 2020, Saarbrücken, Germany not share the burden of proof even between closely related © 2020 Copyright held by the owner/author(s). systems. To take a recent example, there is no easy way to ACM ISBN 978-1-4503-7104-9/20/07. https://doi.org/10.1145/3373718.3394736 transfer the work done in the 80-page-long normalization LICS ’20, July 8–11, 2020, Saarbrücken, Germany Daniel Gratzer, G. A. Kavvos, Andreas Nuyts, and Lars Birkedal proof for MLTTµ [30] to a normalization proof for the modal and we can prove very little about it without additional 2- dependent type theory of Birkedal et al.[14], even though cells. these systems are only marginally different. Put simply, if If we add a 2-cell 휖 : 휇 ⇒ 1 to M, we can define a function one wished to prove that type-checking is decidable for the extract : ⟨휇 | 퐴⟩ → 퐴 latter, then one would have to start afresh. 퐴 We intend to avoid such duplication in the future. Rather inside the type theory. If we also add a 2-cell 훿 : 휇 ⇒ 휇 ◦ 휇 than designing a new dependent type theory for some preor- then we can also define dained of modalities, we will introduce a system that is duplicate : ⟨휇 | 퐴⟩ → ⟨휇 | ⟨휇 | 퐴⟩⟩ parametrized by a mode theory, i.e. an algebraic specification 퐴 of a modal situation. This system, which we call MTT, solves Furthermore, we can control the precise interaction between both problems at once. First, by instantiating it with different duplicate퐴 and extract퐴 by adding more equations that relate mode theories we will show that it can capture a wide class 휖 and 훿. For example, we may ask that M be the walking of situations. Some of these, e.g. the one for guarded recur- comonad [63] which leads to a type theory with a dependent sion, lead to a previously unknown system that improves S4-like modality [27, 57, 67]. We can be even more specific, upon earlier work. Second, the predictable behavior of our e.g. by asking that (휇, 휖, 훿) be idempotent. rules allows us to prove metatheoretic results about large Thus, a morphism 휇 : 푛 → 푚 introduces a modality classes of instantiations of our system. For example, our ⟨휇 | −⟩, and a 2-cell 훼 : 휇 ⇒ 휈 of M allows the definition of canonicity theorem applies irrespective of the chosen mode a function of type ⟨휇 | 퐴⟩ → ⟨휈 | 퐴⟩ @ 푚. theory. As a result, we only need to prove such theorems Relation to other modal type theories. Most work on once. Returning to the previous example, careful choices of modal type theories still defies classification. However, we mode theory yield two systems that closely resemble the can informatively position MTT with respect to two qualita- calculi of Birkedal et al.[14] and MLTT [30] respectively, µ tive criteria, viz. usability and generality. so that our proof of canonicity applies to both. Much of the prior work on modal type theory has fo- In fact, we take things one step further: MTT is not just cused on bolting a specific modality onto a type theory. The multimodal, but also multimode. That is, each judgment of benefit of this approach is that the syntax can be designed MTT can be construed as existing in a particular mode. All to be as convenient as possible for the application at hand. modes have some things in common—e.g. there will be depen- For example, spatial/cohesive type theory [67] features two dent sums in each—but some might possess distinguishing modalities, ♭ and ♯, and is presented in a dual-context style. features. From a semantic point of view, different modes cor- This judgmental structure, however, is applicable only be- respond to different context categories. In this light, modal- cause of the particular properties of ♭ and ♯. Nevertheless, ities intuitively correspond to functors between those cate- the numerous pen-and-paper proofs in op. cit. demonstrate gories: in fact, they will be structures slightly weaker than that the resulting system is easy to use. dependent right adjoints (DRAs) [14]. At the other end of the spectrum, the framework of Licata- Mode theories. At a high level, MTT can be thought of Shulman-Riley (LSR) [44] comprises an extremely general as a machine that converts a concrete description of modes toolkit for simply-typed, substructural modal type theory. and modalities into a type theory. This description, which Its dependent generalization, which is currently under de- is often called a mode theory, is given in the form of a small velopment, is able to handle a very large class of modalities. strict 2- [43, 44, 61]. A mode theory gives rise to the However, this generality comes at a price: its syntax is com- following correspondence: plex and unwieldy, even in the simply-typed case. MTT attempts to strike a delicate balance between those object ∼ mode two extremes. By avoiding substructural settings and some morphism ∼ modality kinds of modalities we obtain a noticeably simpler apparatus. 2-cell ∼ natural map between modalities These restrictions imply that, unlike LSR, we do not need to annotate our term formers with delayed substitutions, The equations between morphisms and between 2-cells in a and that our system straightforwardly extends to dependent mode theory can be used to precisely specify the interactions types. Crucially, we ensure that no rule of MTT ‘trims’ the we want between different modalities. We will illustrate this context, which would necessitate either delayed substitu- point with an example. tions [16, 44] or often delicate admissible rules [10, 14, 30] in order to ensure the validity of substitution. We also show Instantiating MTT. Suppose we have a mode theory that MTT can be used for many important examples, and that M with a single object 푚, a single generating morphism it is simple enough to be used in pen-and-paper calculations. 휇 : 푚 → 푚, and no non-trivial 2-cells. Equipping MTT with M produces a type theory with a single modal type Contributions. In summary, we make the following con- constructor, ⟨휇 | −⟩. This is the simplest non-trivial setting, tributions: Multimodal Dependent Type Theory LICS ’20, July 8–11, 2020, Saarbrücken, Germany

퐴 퐴 푚 • We introduce MTT, a general type theory for multiple that is a small type, and Γ ⊢ type1 @ that it is large. modes and multiple interacting modalities. The itself must be a large type, but otherwise both • We define its semantics, which constitute a category levels are closed under all other connectives. Finally, we of models. introduce an operator that lifts a small type to a large one: • We prove that MTT satisfies canonicity, an important ℓ ≤ ℓ ′ Γ ⊢ 퐴 type @푚 metatheoretic property, subject to technical restriction ℓ 퐴 푚 through a modern gluing argument [5, 24, 37, 66]. Γ ⊢ ⇑ typeℓ′ @ • We instantiate MTT with various mode theories, and The lifting operation commutes definitionally with all the show its value in reasoning about guarded recursion [16], connectives, e.g. ⇑(퐴 → 퐵) = ⇑퐴 → ⇑퐵. We will use large degrees of relatedness [54], and other modal situations. types for the most part: only they will be allowed in contexts, For want of space we omit many details and proofs, which and the judgment Γ ⊢ 푀 : 퐴 @푚 will presuppose that 퐴 is can be found in the accompanying technical report. large. As we will not have terms at small types, we will not need the term lifting operations used by Coquand [23] and 2 The Syntax of MTT Sterling [68]. We now present the syntax of MTT. As mentioned in the We will often suppress ⇑− as well as the isomorphism introduction, the syntax of MTT is parameterized by a small between elements of the universe and types for readability. 2-category called a mode theory. In Section 6, we will instan- tiate MTT with several specific mode theories to recover 2.2 Introducing a Modality particular modal type theories, but at present we will work Having sketched the basic type theory inhabiting each mode, with over an arbitrary mode theory. Accordingly, for the we now show how these type theories interact. rest of this paper we fix a mode theory M, and use 푚, 푛, 표 Suppose M contains a modality 휇 : 푛 → 푚. We would like to stand for modes (the objects of M), 휇, 휈, 휏 for modalities to think of 휇 as a ‘map’ from mode 푛 to mode 푚. Then, for (the morphisms), and 훼, 훽,훾 for 2-cells. each ⊢ 퐴 type @푛 we would like a type ⊢ ⟨휇 | 퐴⟩ type @푚. In broad terms, MTT consists of a collection of type the- On the level of terms we would similarly like for each ⊢ 푀 : ories, one for each mode 푚 ∈ M. These type theories will 퐴 @푛 an induced term ⊢ mod휇 (푀) : ⟨휇 | 퐴⟩ @푚. eventually appear in one another, but only as spectres under These constructs would be entirely satisfactory, were it a modality. We thus begin by describing the individual type not for the presence of open terms. To illustrate the problem, theories at each mode, and only then discuss how modalities suppose we have a type Γ ⊢ 퐴 type @푛. We would hope can be used to relate them. that the corresponding modal type would live in the same context, i.e. that Γ ⊢ ⟨휇 | 퐴⟩ type @푚. However, this is not 2.1 The Type Theory at Each Mode possible, as Γ is only a context at mode 푛, and cannot be Each mode in MTT is inhabited by a standard Martin-Löf carried over verbatim to mode 푚. Hence, the only pragmatic Type Theory (MLTT), and accordingly includes the usual option is to introduce an operation that allows a context to judgments. For example, we have the judgment Γ ctx @푚 cross over to another mode. which states that Γ is a well-formed context in that particular Forming a modal type. There are several different pro- mode 푚. There are likewise judgments for types, terms, and posed solutions to this problem in the literature [e.g. 20, 58]. substitutions at each mode. We will use a Fitch-style discipline [10, 14, 30]: we will re- In lieu of an exhaustive list of rules, we show only the im- quire that 휇 induce an operation on contexts in the reverse portant ones in Fig. 1. Briefly, each mode contains ordinary direction, which we will denote by a lock: intensional type theory with dependent sums, dependent products, intensional identity types, booleans, and one uni- cx/lock 푚 verse. Both sums and products satisfy an 휂-rule. Γ ctx @ Γ, µ ctx @푛 Universes à la Coquand. There are several ways to intro- 휇 duce universes in type theory [34, §2.1.6] [45, 56]. We use the Intuitively, µ휇 behaves like a left adjoint to ⟨휇 | −⟩. However, approach of Coquand [23], which is close to Tarski-style uni- ⟨휇 | −⟩ acts on types while −, µ휇 acts on contexts, so this verses. However, instead of inductively defining codes that cannot be an adjunction. Birkedal et al.[14] call this situation represent particular types, Coquand-style universes come a dependent right adjoint (DRA). A DRA essentially consists with an explicit isomorphism between types and terms of the of a type former R and a context operation L such that universe U. {푁 | L(Γ) ⊢ 푁 : 퐴}  {푀 | Γ ⊢ 푀 : R(퐴)} (†) Nevertheless, if this isomorphism were to cover all types then Girard’s paradox [22] would apply, so we must restrict See Birkedal et al. [14] for a formal definition. it to small types. This, in turn, forces us to stratify our types Just as with DRAs, the MTT formation and introduction 퐴 푚 into small and large. The judgment Γ ⊢ type0 @ states rules for modal types effectively transpose types and terms LICS ’20, July 8–11, 2020, Saarbrücken, Germany Daniel Gratzer, G. A. Kavvos, Andreas Nuyts, and Lars Birkedal

퐴 푚 Γ ⊢ typeℓ @

푚 푚 푚 퐴 푚ℓ ℓ ′ Γ ctx @ Γ ctx @ Γ ctx @ Γ ⊢ typeℓ @ ≤ 푚 푚 퐴 푚 Γ ⊢ U type1 @ Γ ⊢ B typeℓ @ Γ ⊢ ⇑ typeℓ′ @ 푚 퐴 푚 푀, 푁 퐴 푚 푚 퐴 푚 , 푥 퐴 퐵 푚 Γ ctx @ Γ ⊢ typeℓ @ Γ ⊢ : ⇑ @ Γ ctx @ Γ ⊢ typeℓ @ Γ : ⇑ ⊢ typeℓ @ 푀, 푁 푚 푥 퐴 퐵 푚 푥 퐴 퐵 푚 Γ ⊢ Id퐴 ( ) typeℓ @ Γ ⊢ ( : ) → typeℓ @ Γ ⊢ ( : ) × typeℓ @

Figure 1. Selected mode-local rules. across this adjunction: whether we can use a variable in our calculus, the vari- tp/modal tm/modal-intro able rule examines the locks to the right of the variable. The , µ 퐴 푛 , µ 푀 퐴 푛 rule of thumb is this: we should always be able to access Γ 휇 ⊢ typeℓ @ Γ 휇 ⊢ : @ ⟨휇 | 퐴⟩ behind µ . Carrying the −, µ ⊣ ⟨휇 | −⟩ analogy fur- Γ ⊢ ⟨휇 | 퐴⟩ type @푚 Γ ⊢ mod (푀) : ⟨휇 | 퐴⟩ @푚 휇 휇 ℓ 휇 ther, we see that the simplest judgment that fits this, namely It remains to show how to eliminate modal types. Previous Γ, 푥 : ⟨휇 | 퐴⟩, µ휇 ⊢ 푥 : 퐴 @푛, corresponds to the counit. work on Fitch-style calculi [14, 30] has employed elimination To correctly formulate the variable rule, we will require rules which essentially invert the introduction rule tm/modal- one more idea: following modal type theories based on left intro. Such rules remove one or more locks from the context division [1, 2, 54, 55, 57], every variable in the context will during type-checking, and sometimes even trim a part of it. be annotated with a modality, 푥 : (휇 | 퐴). Intuitively a For example, a rule of this sort would be variable 푥 : (휇 | 퐴) is the same as a variable 푥 : ⟨휇 | 퐴⟩, but the annotations are part of the structure of a context while µ ∉ Γ′ Γ ⊢ 푀 : ⟨휇 | 퐴⟩ @푚 휇 ⟨휇 | 퐴⟩ is a type. This small circumlocution will ensure that ′ Γ, µ휇, Γ ⊢ open(푀) : 퐴 @푛 the variable rule respects substitution. This of rule tends to be unruly, and requires delicate The most general form of the variable rule will be able work to prove even basic results about it, such as the admis- to handle the interaction of modalities, so we present it in sibility of substitution: see the technical report by Gratzer stages. A first ‘counit-like’ approximation is then et al.[31] for a particularly laborious case. The results in op. tm/var/counit µ , µ 퐴 푛 cit. could not possibly reuse any of the work of Birkedal et al. ∉ Γ1 Γ0 휇 ⊢ type1 @

[14], as a small change in the syntax leads to many subtle Γ0, 푥 : (휇 | 퐴), µ휇, Γ1 ⊢ 푥 : 퐴 @푛 changes in the metatheory. Consequently, it seems unlikely that one could adapt this approach to a modality-agnostic The first premise requires that no further locks occur in Γ1. setting like ours. Context extension. The switch to modality-annotated We will use a different technique, which is reminiscent declarations 푥 : (휇 | 퐴) also requires us to revise the context of dual-context calculi [39]. First, we will let the variable extension rule. The revised version, cx/extend, appears in rule control the use of modal variables. Then, we will take a Fig. 2 and closely follows the formation rule for ⟨휇 | −⟩: if ‘modal cut’ rule, which will allow the substitution of modal , µ 퐴 푛 Γ 휇 ⊢ type1 @ is a type in the locked context Γ, then we terms for modal variables, to be our modal elimination rule. may extend the context Γ to include a declaration 푥 : (휇 | 퐴), Accessing a modal variable. The behavior of modal types so that 푥 stands for a term of type 퐴 under the modality 휇. can often be clarified by asking a simple question: when can The elimination rule. The difference between a modal we use 푥 : ⟨휇 | 퐴⟩ to construct a term of type 퐴? In previ- type ⟨휇 | 퐴⟩ and an annotated declaration 푥 : (휇 | 퐴) in the ous Fitch-style calculi we would use the modal elimination context is navigated by the modal elimination rule. In brief, rule to reduce the goal to ⟨휇 | 퐴⟩, and then—had the modal its role is to enable the substitution of a term of the former elimination rule not eliminated 푥 from the context—we would type for a variable with the latter declaration. The full rule simply use the variable. We may thus write down a term of is complex, so we first discuss the case of a single modality type 퐴 using a variable 푥 : ⟨휇 | 퐴⟩ only when our context 휇 : 푛 → 푚. The rule for this 휇 is has the appropriate structure, and the final arbiter of that is the modal elimination rule. tm/modal-elim/single-modality ⊢ 푀 ⟨휇 | 퐴⟩ 푚 , 푥 ( | ⟨휇 | 퐴⟩) ⊢ 퐵 푚 MTT turns this idea on its head: rather than handing con- Γ 0 : @ Γ : 1 type1 @ ,푦 휇 퐴 푀 퐵 푦 푥 푚 trol over to the modal elimination rule, we delegate this Γ : ( | ) ⊢ 1 : [mod휇 ( )/ ] @ decision to the variable rule itself. In order to ascertain Γ ⊢ let mod휇 (푦) ← 푀0 in 푀1 : 퐵[푀0/푥] @푚 Multimodal Dependent Type Theory LICS ’20, July 8–11, 2020, Saarbrücken, Germany

Forgetting dependence for a moment, we see that this rule We relax this requirement by allowing for a mediating 2-cell: is close to the dual context style [39, 58]: if we think of tm/var/combined annotations as separating the context into multiple zones, 휇, 휈 : 푛 → 푚 훼 : 휇 ⇒ 휈 then 푦 : (휇 | 퐴) clearly belongs to the ‘modal’ part. Γ, 푥 : (휇 | 퐴), µ ⊢ 푥훼 : 퐴훼 @푛 In the dependent case we also need a motive Γ, 푥 : (1 | ⟨휇 | 휈 퐴 퐵 푚 훼 ⟩) ⊢ type1 @ , which depends on a variable of modal The superscript in 푥 is now part of the syntax: each vari- type, but under the identity modality 1. This premise is then able must be annotated with the 2-cell that ‘unlocks’ it and en- 푀 fulfilled by 0 in the conclusion. In a sense, this rule permits ables its occurrence, though we will still write 푥 to mean 푥1휇 . a form of modal induction: every variable 푥 : (1 | ⟨휇 | 퐴⟩) can The final form of the variable rule, which appears as tm/var 푦 푦 휇 퐴 be assumed to be of the form mod휇 ( ) for some : ( | ). in Fig. 2, is only a slight generalization which allows the This kind of rule has appeared before in dependent modal variable to occur at positions other than the very front of the type theory, mainly in the work of Shulman [67]. context. In fact, tm/var can be reduced to tm/var/combined In the type theory of Birkedal et al.[14] modalities are by using weakening to remove variables to the right of 푥, taken to be dependent right adjoints, with terms witnessing and then invoking functoriality to fuse all the locks to the † Eq. ( ). This isomorphism can encode tm/modal-elim/single- right of 푥 into a single one with modality locks(Γ1). modality, but that rule alone cannot encode Eq. (†). As a result, modalities in MTT are weaker than DRAs. The full elimination rule. Recall that the elimination rule for a single modality (tm/modal-elim/single-modality) 2.3 Multiple Modalities allowed us to plug a term of type ⟨휇 | 퐴⟩ for an assumption 푥 휇 퐴 Thus far we have only considered a single modality. In this : ( | ). Some additional generality is needed to cover 푥 휈 휇 퐴 퐵 푚 section we discuss the small changes that are needed to the case where the motive : ( | ⟨ | ⟩) ⊢ type @ 푥 휈 support multiple interacting modalities. The final version of depends on under a modality ≠ 1. This is where the the modal rules is given in Fig. 2. composition of modalities in M comes in handy: our new rule will use it to absorb 휈 by replacing the assumption 푥 : Multimodal locks. We have so far only used the opera- (휈 | ⟨휇 | 퐴⟩) with 푥 : (휈 ◦ 휇 | 퐴). , µ 휇 푛 푚 tion − 휇 on contexts for the single modality : → . The new rule, tm/modal-elim, is given in Fig. 2. The sim- This operation also works for any modality with the same pler rule may be recovered by setting 휈 ≜ 1. In this simpler rule cx/lock, hence expressing an action of locks on con- case, we will suppress the subscripted 1 on let, just as in texts that is contravariant with respect to the mode. The tm/modal-elim/single-modality. However, many natural ex- only question is how these locks should interact, and this amples require eliminations where 휈 ≠ 1. For instance, in is where the mode theory comes in: locks should be func- Section 3 we show that ⟨휈 ◦ 휇 | 퐴⟩ ≃ ⟨휈 | ⟨휇 | 퐴⟩⟩. The func- 휈 표 푛 휇 푛 푚 푚 torial, so that : → , : → , and Γ ctx @ imply tion from the right-hand side to the left crucially depends on , µ , µ , µ 표 Γ 휇 휈 = Γ 휇◦휈 ctx @ . We additionally ask that the iden- the ability to pattern-match on a variable 푥 : (휈 | ⟨휇 | 퐴⟩), 푚 푚 tity modality 1 : → at each mode has a trivial, invisible which requires the stronger tm/modal-elim. action on contexts, i.e. Γ, µ1 = Γ. These two actions, which are encoded by cx/compose and Modal dependent products. In the technical report we cx/id, ensure that µ is a contravariant functor on M, map- have supplemented MTT with a primitive modal dependent ping each mode 푚 to the category of contexts Γ ctx @푚. The , (푥 : (휇 | 퐴)) → 퐵, which bundles together contravariance originates from the fact that M is a specifi- ⟨휇 | −⟩ and the ordinary product. If we ignore 휂-equality, cation of the behavior of the modalities ⟨휇 | −⟩, so that their (푥 : (휇 | 퐴)) → 퐵 can be defined as (푥0 : ⟨휇 | 퐴⟩) → 푥 푥 퐵 Î left-adjoint-like counterparts −, µ휇 act with the opposite (let mod휇 ( ) ← 0 in ). This modal -type is convenient variance. for programming but it is not essential, so we defer further discussion to the technical report. The full variable rule. We have seen that µ induces a functor from M to categories of contexts, but we have not Definitional equality in MTT. A perennial problem in yet used the 2-cells of M. In short, a 2-cell 훼 : 휇 ⇒ 휈 type theory is that of deciding where the boundary between contravariantly induces a substitution from Γ, µ휈 to Γ, µ휇. derviable and definitional equalities should lie. We have fol- We will discuss this further in Section 4, but for now we only lowed standard practices regarding definitional equalities for mention that this gives rise to an admissible operation on dependent products, sums, etc.. The situation is somewhat types: for each 2-cell we obtain an operation (−)훼 such that more complicated regarding modal types. On the one hand, 훼 Γ, µ휇 ⊢ 퐴 type @푚 implies Γ, µ휈 ⊢ 퐴 type @푚. we have the expected 훽-rule tm/modal-beta (see Fig. 2). On In order to prove the admissibility of this operation we the other hand, we do not include any definitional 휂-rules: need a more expressive variable rule that builds in the action as the eliminator is a positive pattern-matching construct, of 2-cells. The first iteration (tm/var/counit) required that the proper 휂-rule would need commuting conversions, which the lock and the variable annotation were an exact match. would enormously complicate the metatheory. LICS ’20, July 8–11, 2020, Saarbrücken, Germany Daniel Gratzer, G. A. Kavvos, Andreas Nuyts, and Lars Birkedal

Γ ctx @푚

cx/lock cx/extend 휇 푛 푚 푚 휇 푛 푚 푚 , µ 퐴 푛 : → Γ ctx @ : → Γ ctx @ Γ 휇 ⊢ type1 @ Γ, µ휇 ctx @푛 Γ, 푥 : (휇 | 퐴) ctx @푚

cx/id cx/compose Γ ctx @푚 휈 : 표 → 푛 휇 : 푛 → 푚 Γ ctx @푚

Γ = Γ, µ1 ctx @푚 Γ, µ휇, µ휈 = Γ, µ휇◦휈 ctx @표

퐴 푚 푀 퐴 푚 Γ ⊢ typeℓ @ Γ ⊢ : @

tp/modal tm/var tm/modal-intro 휇 푛 푚 , µ 퐴 푛 휈 푚 푛 훼 휈 휇 푛 푚 , µ 푀 퐴 푛 : → Γ 휇 ⊢ typeℓ @ : → : ⇒ locks(Γ1) : → Γ 휇 ⊢ : @ 휇 퐴 푚 , 푥 휈 퐴 , 푥훼 퐴훼 푚 푀 휇 퐴 푚 Γ ⊢ ⟨ | ⟩ typeℓ @ Γ0 : ( | ) Γ1 ⊢ : @ Γ ⊢ mod휇 ( ) : ⟨ | ⟩ @

tm/modal-elim 휇 푛 푚 휈 푚 표 , 푥 휈 휇 퐴 퐵 표 : → : → Γ : ( | ⟨ | ⟩) ⊢ type1 @ Γ, µ휈 ⊢ 푀0 : ⟨휇 | 퐴⟩ @푚 Γ, 푥 : (휈 ◦ 휇 | 퐴) ⊢ 푀1 : 퐵[mod휇 (푥)/푥] @표

Γ ⊢ let휈 mod휇 (푥) ← 푀0 in 푀1 : 퐵[푀0/푥] @표

tm/modal-beta 휈 푚 표 휇 푛 푚 , 푥 휈 휇 퐴 퐵 표 : → : → Γ : ( | ⟨ | ⟩) ⊢ type1 @ Γ, µ휈◦휇 ⊢ 푀0 : 퐴 @푛 Γ, 푥 : (휈 ◦ 휇 | 퐴) ⊢ 푀1 : 퐵[mod휇 (푥)/푥] @표

Γ ⊢ let휈 mod휇 (푥) ← mod휇 (푀0) in 푀1 = 푀1 [푀0/푥] : 퐵[mod휇 (푀0)/푥] @표

locks(Γ)

locks(·) = 1 locks(Γ, 푥 : (휇 | 퐴)) = locks(Γ) locks(Γ, µ휇) = locks(Γ) ◦ 휇

Figure 2. Selected modal rules.

, µ 퐴 푚 3 Programming with Modalities equivalence [70, §4]. Fixing Γ 휇◦휈 ⊢ type1 @ , let In this section we show how MTT can be used to program 휇 휈 퐴 휇 휈 퐴 and reason with modalities. We develop a toolkit of modal comp휇,휈 : ⟨ | ⟨ | ⟩⟩ → ⟨ ◦ | ⟩ 푥 푥 푥 combinators, which we then use in Section 3.2 to effortlessly comp휇,휈 ( ) ≜ let mod휇 ( 0) ← in present a type theory for an idempotent comonad. let휇 mod휈 (푥1) ← 푥0 in mod휇◦휈 (푥1) 3.1 Modal Combinators We first show how each 2-cell 훼 : 휇 ⇒ 휈 with 휇, 휈 : 푛 → 푚 and induces a natural transformation ⟨휇 | −⟩ → ⟨휈 | −⟩, which comp-1 : ⟨휇 ◦ 휈 | 퐴⟩ → ⟨휇 | ⟨휈 | 퐴⟩⟩ , µ ⊢ 퐴 푚 휇,휈 we call a coercion. Given Γ 휇 type1 @ , we define -1 푥 푥 푥 푥 comp휇,휈 ( ) ≜ let mod휇◦휈 ( 0) ← in mod휇 (mod휈 ( 0)) coe[훼 : 휇 ⇒ 휈](−) : ⟨휇 | 퐴⟩ → ⟨휈 | 퐴훼 ⟩ 훼 휇 휈 푥 푥 푥 푥훼 We elide the 2-cell annotations on variables, as they are all coe[ : ⇒ ]( ) ≜ let mod휇 ( 0) ← in mod휈 ( 0 ) identities (i.e. we only need tm/var/counit). Even in this With this operation, we have completed the correspondence small example the context equations that involve locks are from Section 1: objects of M correspond to modes, mor- essential: for ⟨휇 | ⟨휈 | 퐴⟩⟩ to be a valid type we need that phisms to modalities, and 2-cells to coercions. Γ, µ휇, µ휈 = Γ, µ휇◦휈 , which is ensured by cx/compose. Fur- 휇 휇 We can also show that the assignment ↦→ ⟨ | −⟩ is, thermore, observe that comp휇,휈 crucially relies on the mul- in some sense, functorial. Unlike the action of locks, this timodal elimination rule tm/modal-elim: we must pattern- functoriality is not definitional, but only a type-theoretic match on 푥0, which is under 휇 in the context. Multimodal Dependent Type Theory LICS ’20, July 8–11, 2020, Saarbrücken, Germany

These combinators are only propositionally inverse. In We can show that ⟨휇 | 퐴⟩ is a comonad by defining the one direction, the proof is expected operations using the combinators of Section 3.1: 푥 휇 휈 퐴 푥, -1 푥 휇 퐴 휇 휇 퐴 휇 퐴 퐴휖 _ : ( : ⟨ | ⟨ | ⟩⟩) → Id⟨휇 | ⟨휈 |퐴⟩⟩ ( comp휇,휈 (comp휇,휈 ( ))) dup퐴 : ⟨ | ⟩ → ⟨ | ⟨ | ⟩⟩ extract퐴 : ⟨ | ⟩ → _ ≜ 휆푥. let mod휇 (푥0) ← 푥 in let휇 mod휈 (푥1) ← 푥0 in -1 휖 휇 dup퐴 ≜ comp휇,휇 extract퐴 ≜ coe[ : ⇒ 1] refl(mod휇 (mod휈 (푥))) We must also show that dup퐴 and extract퐴 satisfy the como- This is a typical example of reasoning about modalities: we nad laws, but that automatically follows from general facts use the modal elimination rule to induct on a modally-typed pertaining to coe and comp.1 This is indicative of the benefits (−) term. This reduces it to a term of the form mod , and the of using MTT: every general result about it also applies to result follows definitionally. It is equally easy to construct this instance, including the canonicity theorem of Section 5. an equivalence ⟨1 | 퐴⟩ ≃ 퐴. As a final example, we will show that each modal type 4 The Substitution Calculus of MTT satisfies the K , a central axiom of Kripke-style modal Until this point we have presented a curated, high-level logics. This combinator will be immediately recognizable to view of MTT, and we have avoided any discussion of its functional programmers as the term that shows that ⟨휇 | −⟩ metatheory. Yet, syntactic matters can be quite complex, and is an applicative functor [48]. have historically proven to be sticking points for modal type − ⊛휇 − : ⟨휇 | 퐴 → 퐵⟩ → ⟨휇 | 퐴⟩ → ⟨휇 | 퐵⟩ theory. While such details are not necessary for the casual 푓 ⊛휇 푎 ≜ let mod휇 (푓0) ← 푓 in reader, it is essential to validate that MTT is syntactically let mod휇 (푎0) ← 푎 in well-behaved, enjoying e.g. a substitution principle. mod휇 (푓0 (푎0)) We have opted for a modern approach in the analysis We can also define a stronger combinator, which corresponds of MTT by presenting it as a generalized algebraic theory to a dependent form of the Kripke axiom [14], and which (GAT) [18, 38]. While this simplifies the study of its seman- tics (see Section 5), it can also be used to study the syntax. generalizes ⊛휇 to dependent products (푥 : 퐴) → 퐵(푥). This operation has precisely the same implementation as For example, the formulation of MTT as a GAT naturally the simply-typed case, but the type is more complex: leads us to include explicit substitutions [25, 29, 47] in the syntax. Thus, substitution in MTT is not a metatheoretic 휇 푥 퐴 퐵 ⟨ | ( : ) → ⟩ → operation on raw terms, but a piece of the syntax. This pre- (푥0 : ⟨휇 | 퐴⟩) → (let mod휇 (푥) ← 푥0 in ⟨휇 | 퐵⟩) sentation helps us carefully state the equations that govern substitutions and their interaction with type formers. We In order to ensure that ⟨휇 | 퐵⟩ is well-typed, the context consequently obtain an elegant substitution calculus, which must contain 푥 : (휇 | 퐴), but instead we have bound 푥 : (1 | 0 can often be quite complex for modal type theories. We only ⟨휇 | 퐴⟩). We correct this mismatch by eliminating 푥 and 0 discuss the modal aspects of substitution here; the full calcu- binding the result to 푥, which bestows on it the correct type. lus may be found in the technical report. 3.2 Idempotent Comonads in MTT Modal substitutions. In addition to the usual rules, MTT A great deal of prior work in modal type theory has focused features substitutions corresponding to the 1- and 2-cells of on comonads [27, 30, 58, 67], and in particular idempotent the mode theory. First, recall that for each modality 휇 : 푛 → comonads. Shulman [67, Theorem 4.1] has shown that such 푚 we have the operation µ휇 on contexts. In keeping with modalities necessitate changes to the judgmental structure, the algebraic syntax, we will write −.µ휇 instead of −, µ휇 in as the only idempotent comonads that are internally defin- this section. We extend its action to substitutions: able in type theory are of the form −×푈 for some proposition sb/lock 푈 . In this section we present a mode theory for idempotent 휇 : 푛 → 푚 Γ ⊢ 훿 : Δ @푚 comonads, and prove that the resulting type theory internally Γ.µ휇 ⊢ 훿.µ휇 : Δ.µ휇 @푛 satisfies the expected equations, using just the combinators 훼 휇 휈 of the previous section. Second, each 2-cell : ⇒ induces a natural transforma- tion between µ휈 and µ휇, whose component at Γ is We define the mode theory Mic to consist of a single mode 푚, and a single non-trivial morphism 휇 : 푚 → 푚. We will sb/key enforce idempotence by setting 휇 ◦ 휇 = 휇. Finally, in order to 훼 : 휇 ⇒ 휈 induce a morphism ⟨휇 | 퐴⟩ → 퐴 we include a unique non- .µ ¤훼 .µ 푛 Γ 휈 ⊢ Γ : Γ 휇 @ trivial 2-cell 휖 : 휇 ⇒ 1. In order to ensure that this 2-cell to be Mcoop unique, we add equations such as 휖 ★1 = 1 ★휖 : 휇 ◦ 휇 ⇒ 휇, Recalling that is the 2-category with morphisms and 휇 휇 M where ★ denotes the horizontal composition of 2-cells. The 2-cells opposite from , we see that these substitutions resulting mode theory is a 2-category, albeit a very simple 1In particular, our modal combinators satisfy a variant of the interchange one: it is in fact only a poset-enriched category. law of a 2-category. LICS ’20, July 8–11, 2020, Saarbrücken, Germany Daniel Gratzer, G. A. Kavvos, Andreas Nuyts, and Lars Birkedal

−.µ ¤훼 come with equations that ensure that 휇 is a functor, Γ Mode-local structure. Recall that MTT is divided into is a natural transformation, and that together they form a several modes, each of which is closed under the standard 2-functor Mcoop → Cat: see Fig. 3. connectives of MLTT. Accordingly, a model of MTT requires While it is no longer necessary to prove that substitution a CwF for each mode 푚 ∈ M: a small category [푚], a is admissible, we would like to show that explicit substitu- presheaf of types T푚 : PSh(Te푚) and a presheaf of terms ∫ tions can be pushed inside terms, and ultimately eliminated Te푚 : PSh( T푚). Each CwF is required to be a model of on closed terms. The proof of canonicity (Theorem 5.5) im- MLTT with Í, Î and Id types, and a Coquand-style universe. plicitly contains such an algorithm, but that is overkill: a This part of the definition is entirely standard, and canbe simple, direct argument proves that explicit substitutions found in the literature [9, 28, 34]. The novel portion of a MTT can be propagated down to variables. model describes the relations between CwFs induced by the Moreover, we may define the admissible operation men- 1- and 2-cells of M. tioned in Section 2.3 by letting 퐴훼 ≜ 퐴[¤훼 ], and using this Γ 푚 휇 푛 푚 algorithm to derive steps that eliminate the ‘key’ substitu- Locks and keys. Recall that for Γ ctx @ and : → , 푛 tion. we have a context Γ µ휇 ctx @ , and that this construction extends functorially to substitutions. Hence, we will require Pushing substitutions under modalities. In order for for each modality 휇 : 푛 → 푚 a functor µ휇 : C[푚] → C[푛]. the aforementioned algorithm to work, we must specify Similarly, each 훼 : 휇 ⇒ 휈 induces a naturalJ K transformation how substitutions commute with the modal connectives of from −, µ휈 to −, µ휇. Accordingly, a model should come with 훼 MTT. Unlike previous work [31], the necessary equations a natural transformation ¤ : µ휈 ⇒ µ휇 . Moreover, J K J K J K are straightforward: the equalities of Fig. 3 require that the assignments 휇 ↦→ µ휇 훼 ↦→ ¤훼 ⟨휇 | 퐴⟩[훿] = ⟨휇 | 퐴[훿.µ ]⟩ and be strictly 2-functorial. Thus, this part of the 휇 model can be succinctly summarized by requiring a 2-functor 푀 훿 푀 훿.µ mod휇 ( )[ ] = mod휇 ( [ 휇]) C[−] : Mcoop → Cat. The contravariance accounts for the 휇 ⟨휇 | −⟩ µ This simplicity is not coincidental. Previous modal type fact corresponds to , but that the functor 휇 , µ J K theories included rules that, in one way or another, trimmed models − 휇, which acts with the opposite variance. the context during type checking: some removed variables [58, Modal comprehension structure. Context declarations 60, 67], while others erased context formers, e.g. locks [14, in MTT are annotated with a modality, and the context exten- 30]. In either case, it was necessary to show that the trim- sion rule cx/extend involves locks. Thus, our CwFs should be ming operation, which we may write as ∥Γ∥, is functorial: equipped with more structure than mere context extension 훿 훿 Γ ⊢ : Δ should imply ∥Γ∥ ⊢ ∥ ∥ : ∥Δ∥. Unfortunately, the to support it. proof of this fact is almost always very complicated. Some Recall that, in an ordinary CwF C, given a context Γ ∈ C type theories avoid it by ‘forcing’ substitution to be admis- and a type 퐴 ∈ T(Γ) we have a context Γ.퐴 along with a sible using delayed substitutions [12, 44], but this causes substitution p : Γ.퐴 → Γ, and a term q ∈ T(e Γ.퐴, 퐴[p]). serious complications in the equational theory. To model MTT we need a modal comprehension operation, MTT circumvents this by avoiding any context trimming. which for each context Γ ∈ C[푚], modality 휇 : 푛 → 푚, and As a result, we need neither delayed substitutions nor a type 퐴 ∈ T푛 ( µ휇 (Γ)) yields complex proof of admissibility. J K • a context Γ.(휇 | 퐴) ∈ C[푚], 5 The Semantics of MTT • a substitution p : Γ.(휇 | 퐴) → Γ, and • a term q ∈ Te푛 ( µ휇 (Γ.(휇 | 퐴)), 퐴[ µ휇 (p)]) As mentioned in Section 4, we have structured MTT as a . 휇 퐴 J K J K GAT. As a result, MTT automatically induces a category where Γ ( | ) is universal in an appropriate sense. of models and (strict) homomorphisms between them [18, Intuitively, q corresponds to tm/var/counit. As mentioned 38]. However, this notion of model follows the syntax quite before, this suffices to model the full variable rule tm/var, as 훼 closely. In order to work with it more effectively we factor it p, ¤−, and q can be used to define it from tm/var/counit. into pieces, using the more familiar definition of categories 2 Modal type structure. The interpretation of the modal with families (CwFs) [28]. We will then use this notion of type ⟨휇 | −⟩ for a modality 휇 : 푛 → 푚 requires operations model to present a semantic proof of canonicity via gluing [5, for the formation, introduction, and elimination rules. Just 24, 37, 66]. as with the other connectives, these are a direct transla- Like MTT itself, the definition of model is parametrized tion of the rules tp/modal, tm/modal-intro, and tm/modal- by a mode theory, so we fix a mode theory M. elim to the language of CwFs. For example, for every Γ ∈ 푚 퐴 µ 푀 µ , 퐴 2 C[ ], ∈ T푛 ( 휇 (Γ)), and ∈ Te푛 ( 휇 (Γ) ), we re- In the technical report we have used a more categorical presentation of J K J K CwFs, known as natural models [9]. However, in the interest of clarity we quire mod휇 (푀) ∈ Te푚 (Γ, Mod휇 (퐴)). state our results in terms of CwFs here. This discussion leads to the following definition. Multimodal Dependent Type Theory LICS ’20, July 8–11, 2020, Saarbrücken, Germany

sb/lock-id sb/id-lock sb/lock-compose 휇 : 푛 → 푚 Γ ⊢ 훿 : Δ @푚 휇 : 푛 → 푚 Γ0 ⊢ 훾1 : Γ1 @푚 Γ1 ⊢ 훾2 : Γ2 @푚

Γ.µ휇 ⊢ id.µ휇 = id : Γ.µ휇 @푛 Γ ⊢ 훿.µ1 = 훿 : Δ @푚 Γ0.µ휇 ⊢ (훾2 ◦ 훾1).µ휇 = (훾2.µ휇) ◦ (훾1.µ휇) : Γ2.µ휇 @푚

sb/compose-lock sb/natural 휇 : 푛 → 푚 휈 : 표 → 푛 Γ ⊢ 훿 : Δ @푚 휇, 휈 : 푛 → 푚 훼 : 휈 ⇒ 휇 Γ ⊢ 훿 : Δ @푚 .µ 훿.µ 훿.µ .µ .µ 푚 .µ ¤훼 훿.µ 훿.µ ¤훼 .µ 푛 Γ 휇◦휈 ⊢ 휇◦휈 = 휇 휈 : Δ 휇◦휈 @ Γ 휇 ⊢ Δ ◦ ( 휇) = ( 휈 ) ◦ Γ : Δ 휈 @

Figure 3. Selection of rules from the equational theory of modal substitutions.

Definition 5.1. A model of MTT is a 2-functor C[−] : through a logical relation [46, 69]. However, this method be- Mcoop → Cat, equipped with the following structure: comes very complicated when we have universes, as their presence makes the definition by induction on types impos- • for each 푚 ∈ M, a CwF (C[푚], T푚, Te푚) that is closed under Î, Í, Id, and U, sible. It is instead necessary to construct a (large) relation • a modal comprehension structure for M on these on types, which associates a pair of types with a PER; the CwFs, and logical relation on terms is then subordinated to this relation • for each modality 휇 : 푛 → 푚, a modal type structure on types [4, 6]. This technique requires significant effort, and , , involves many proofs by simultaneous induction. (Mod휇 mod휇 open휇). This approach can be simplified by replacing proof-irrelevant 퐹 Definition 5.2. A morphism between models : C[−]1 → logical relations by a proof-relevant gluing construction [49]. C[−]2 is a strict 2-natural transformation such that each This leads to the construction of a model in which (a) types 퐹 푚 푚 푚 : C[ ]1 → C[ ]2 is part of a strict CwF morphism [19] are paired with proof-relevant predicates and (b) terms are which strictly preserves modal comprehension and types. equivalence classes of syntactic terms, along with a (type- We observed in Section 2.3 that modalities in MTT are determined) proof of their canonicity. The proof-relevance weaker than DRAs [14].3 Since DRAs are often easier to is crucial in the case of the universe, which contains not just 퐴 (퐴) construct, we make this relation formal. the canonicity data for : U but also the predicate for El . In order to simplify the construction of the glued model, Theorem 5.3. A 2-functor C[−] : Mcoop → Cat satisfying we add an additional definitional equality to MTT, namely the following two conditions induces a model of MTT: ·.µ휇 = · ctx @푚. This equation is satisfied by all the con- 1. for each 푚 ∈ M, there is a CwF (C[푚], T푚, Te푚) that is crete examples described in Section 6. Semantically, it states closed under Î, Í, Id, and U. that the functors µ휇 strictly preserve the chosen terminal J K 2. for each 휇 : 푛 → 푚, µ휇 : C[푚] → C[푛] has a DRA. objects. Without this assumption we would have to establish J K canonicity not just for terms in the empty context, but for In practice virtually all the models of MTT that we con- terms in a locked empty context, i.e. of the form ·.µ휇. This sider will be constructed by applying Theorem 5.3. We can would semantically correspond to gluing along the nerve of also use it to immediately prove consistency: the inclusion of locked empty contexts into the categories Corollary 5.4. There is no closed term of type IdB (tt, ff). of contexts. This situation is comparable to that of proving canonicity for cubical type theories, where it is necessary to C Proof. By Theorem 5.3, any model of MLTT is a valid consider terms with open dimension variables [7, 35]. How- C model of MTT: send each mode to , and each modality to ever, the attendant glued model is complex, so we restrict ( , ) the identity. Therefore, a closed term of type IdB tt ff in this discussion to this simpler and more common case. MTT would also be a term of the same type in MLTT. We The full details of the glued model can be found in the may therefore reduce the consistency of MTT to that of a technical report. Once we construct it, the initiality of syn- model of MLTT, and in particular the set-theoretic one. □ tax [18, 38] provides a witness of canonicity for every term. 5.1 Canonicity Theorem 5.5 (Canonicity). If we extend MTT with the def- We can now use MTT models to prove canonicity via glu- initional equality ·.µ휇 = · ctx @푚 for all modalities 휇, for ing. Canonicity is an important metatheoretic result: it es- every closed term · ⊢ 푀 : 퐴 @푚 the following conditions hold: tablishes the computational adequacy of MTT by ensuring • If 퐴 = B, then · ⊢ 푀 = 푏¯ : B @푚 where 푏¯ ∈ {tt, ff}. that every closed term already is in or is equal to a canon- 퐴 푁 , 푁 푁 푁 퐴 푚 • If = Id퐴0 ( 0 1) then · ⊢ 0 = 1 : 0 @ and ical form—a value. Canonicity is traditionally established 푀 푁 푁 , 푁 푚 · ⊢ = refl( 0) : Id퐴0 ( 0 1) @ . 3While Birkedal et al.[14] only consider endofunctors, there is no obstacle • If 퐴 = ⟨휇 | 퐴0⟩ then there is a term · ⊢ 푁 : 퐴0 @푛 such to extending the definition of a DRA to different categories. that · ⊢ 푀 = mod휇 (푁 ) : ⟨휇 | 퐴0⟩ @푚. LICS ’20, July 8–11, 2020, Saarbrücken, Germany Daniel Gratzer, G. A. Kavvos, Andreas Nuyts, and Lars Birkedal

6 Applying MTT 훾 We will now show concretely how MTT can be used in spe- 훿 ◦ 훾 ≤ 1 1 = 훾 ◦ 훿 ℓ 푡 푠 cific modal situations by varying the mode theory. We will fo- 1 ≤ ℓ 훾 = 훾 ◦ ℓ cus on two different examples: guarded recursion [16, 21, 51], 훿 which captures productive recursive definitions through a combination of modalities, and adjoint modalities [43, 44, 61, 67, 71], where two modalities form an adjunction internal to Figure 4. M푔: a mode theory for guarded recursion. the type theory. In both cases we will show how to recon- struct examples from op. cit. in MTT. The case of guarded 3. include Löb induction as an axiom. recursion is particularly noteworthy, as the specialization of To begin, we define M푔 to be the mode theory generated MTT to the appropriate mode theory leads to a new syntax by Fig. 4. We require that M푔 is poset-enriched, i.e. that which is considerably simpler than previous work. there is at most one 2-cell between a pair of modalities, 휇, 휈, 휇 ≤ 휈 M 6.1 Guarded Recursion which we denote when it exists. As 푔 is not a full 2-category, we do not need to state any coherence equations The key idea of guarded recursion [51] is to use the later between 2-cells. modality ( ) to mark data which may only be used after some Unlike prior guarded type theories, Fig. 4 has two modes. progress has been made, thereby enforcing productivity at We will think of elements of 푠 as being constant types and the level of types. Concretely, the later modality is equipped terms, while types in 푡 may vary over time. The reason for with three basic operations: enforcing this division will become apparent in Theorem 6.3, next : 퐴 → 퐴 (⊛) : (퐴 → 퐵) → 퐴 → 퐵 but for now observe that we can construct an idempotent     comonad 푏 ≜ 훿 ◦ 훾. löb : ( 퐴 → 퐴) → 퐴 ⟨푏 | −⟩ ⟨ℓ | −⟩  Lemma 6.1. is an idempotent comonad and The first two operators make into an applicative func- is an applicative functor. tor [48] while the third, which is known as Löb induction, encodes guarded recursion: it enables us to define a term Proof. Follows from the combinators in Section 3. □ recursively, provided the recursion is provably productive. Next, Eq. (∗), which was hard to force in previous type The perennial example is, of course, the guarded 훾 ◦ ℓ = 훾 theories, is provable: as the combinator comp푏,ℓ type Str퐴  퐴 × Str퐴. This recursive type requires that the from Section 3.1 has the appropriate type: head of the stream is immediately available, but the tail may 푏 ℓ 퐴 푏 ℓ 퐴 푏 퐴 only be accessed after some productive work has taken place. comp푏,ℓ : ⟨ | ⟨ | ⟩⟩ ≃ ⟨ ◦ | ⟩ = ⟨ | ⟩ This allows us to e.g. construct an infinite stream of ones: In order to construct the intended model, recall that the stan- inf_stream_of_ones ≜ löb(푠. (1, 푠)) dard interpretation of guarded type theory uses the of trees PSh(휔): see Birkedal et al.[15] for a thorough discus- However, Str퐴 does not behave like a coinductive type: we sion. Crucially, it is easy to see that = Δ ◦ Γ, where may only define causal operations on streams, which ex- 2 cludes commonplace operations such as tail. In order to Γ : PSh(휔) → Set Δ : Set → PSh(휔) regain coinductive behavior, Clouston et al.[21] introduced Γ ≜ 푋 ↦→ Hom(1, 푋) Δ ≜ 푆 ↦→ 휆_. 푆 a modality (‘always’), an idempotent comonad for which As both Set and PSh(휔) are models of MLTT [15, 34], we 2 퐴 ≃ 퐴. (∗) may use Theorem 5.3 to construct the intended model. Combining this modality2  with 2has proved rather tricky: Theorem 6.2. There exists a model of MTT with this mode previous work has used delayed substitutions [16], or has theory where ⟨푏 | −⟩ is interpreted as and ⟨ℓ | −⟩ as . replaced with clock quantification [8, 10, 17, 50]. The for- Proof. We construct the 2-functor which2 sends 푠 ↦→ Setand mer poses2 serious implementation issues, and—while more 푡 ↦→ PSh(휔). We define µℓ , µ훿 , and µ훾 to be the left flexible—the latter does not enjoy the conceptual simplicity J K J K J K of a single modality. In contrast, MTT enables us to effort- adjoints of , Δ, and Γ respectively [14, 53]. □  lessly combine the two modalities and satisfy Eq. (∗). From this point onwards we will write ≜ ⟨ℓ | −⟩, Δ ≜ MTT To encode guarded recursion inside , we must ⟨훿 | −⟩, and ≜ ⟨훿 ◦ 훾 | −⟩.  1. choose a mode theory which induces an applicative The only thing2 that remains is to add Löb induction. This functor and a comonad satisfying Eq. (∗), is a modality-specific operation that cannot be expressed in 2. construct the intended model2 of MTT with this mode the mode theory, so we must add it as an axiom: see Fig. 5 theory, i.e. a model where these modalities are inter- for the precise formulation. Unfortunately, the addition of an preted in the standard way [15], and axiom means that the canonicity theorem no longer applies. Multimodal Dependent Type Theory LICS ’20, July 8–11, 2020, Saarbrücken, Germany

tm/lob ≤ 휇 휂 : 1 ⇒ 휇 ◦ 휈 Γ, 푥 : (ℓ | 퐴1 ℓ ) ⊢ 푀 : 퐴 @ 푡 휖 : 휈 ◦ 휇 ⇒ 1 Γ ⊢ löb(푥. 푀) : 퐴 @ 푡 푛 푚 1휇 = (1휇 ★ 휖) ◦ (휂 ★ 1휇) 휈 tm/lob-beta 1 = (휖 ★1 ) ◦ (1 ★휂) Γ, 푥 : (ℓ | 퐴1≤ℓ ) ⊢ 푀 : 퐴 @ 푡 휈 휈 휈

Γ ⊢ löb(푥. 푀) = let modℓ (푥) ← next(löb(푥. 푀)) in 푀 : 퐴 @ 푡 Figure 6. Madj: a mode theory for adjunctions

Figure 5. Axiomatization of Löb induction in MTT

However, adding it to the type theory is sound, as the model a term of the following type: supports it. At this point we may as well assume equality reflection [36], as is commonplace in previous guarded type ((푎0,푎1 : 퐴) → Id(푓 (푎0, 푎1), 푓 (푎1, 푎0))) → theories [16]. This is stronger than necessary (function ex- (푠0, 푠1 : Str(퐴)) → Id(zipWith(푓 , 푠0, 푠1), zipWith(푓 , 푠1, 푠0)) tensionality would suffice), but it simplifies proofs and makes comparison to previous work more direct. All things considered, instantiating MTT with M푔 yields Programming with Guarded MTT. We can now use a highly expressive guarded dependent type theory with MTT to program with and reason about guarded recursion. coinductive types. Unlike prior systems, e.g.that of Bahr et al. For instance, we can define coinductive streams: [10], we do not need clock variables or syntactic checks of constancy. Moreover, the syntax is more robust than previous Str : U → U @ 푠 work that combines and [16, 21], as there is no need for Str(퐴) ≜ Γ(löb(푆. Δ(퐴) × 푆)) delayed substitutions.2 Unfortunately, the addition of the Löb Unlike prior guarded type theories, we have defined this axiom means our canonicity theorem (Theorem 5.5) does stream operator not in mode 푡, which represents PSh(휔), not apply, but the syntax remains sound and tractable. but in mode 푠, which represents Set. Accordingly, this def- 퐴 푡 inition does not use . It first uses Δ to convert to a - 6.2 Internal Adjunctions type, and then Γ to move the recursive definition back to 푠. 2 We have by now considered many poset-enriched mode the- This alleviates some bookkeeping: in previous work [16] the ories, i.e. ones where there is at most one 2-cell between stream type was coinductive only if 퐴 was a constant type any pair of modalities. This has worked well for describing (i.e. 퐴 ≃ 퐴). Accordingly, theorems about streams had to strict structures (Section 3.2), as well as some specific set- pass around proofs that the type of elements of the stream 2 tings (Section 6.1). However, we would like to use MTT to is constant. In our case, defining Str at mode 푠 automatically reason about less strict categorical models. In this section ensures that. Hence, Str(퐴) is equivalent to the familiar defi- we will show that we can readily use MTT to reason about a nition, but it is no longer necessary to carry through proofs pair 휈 ⊣ 휇 of adjoint modalities. of constancy. Therefore, for any 퐴 : U @푠 we have Adjoint modalities are common in modal type theory, Theorem 6.3. Str(퐴) is the final coalgebra for 푆 ↦→ 퐴 × 푆 in much in the same way that adjunctions are ubiquitous in mode 푠. mathematics [42–44, 61, 67]. For example, the adjunction 훿 ⊣ 훾 played an important role in the previous section. How- We can also program with Str(퐴) by more directly appeal- ever, that particular case is unusually well-behaved, as it ing to the underlying guarded structure. For instance, we can arises from a Galois connection. In contrast, the behavior of define a ‘zip with’ function. Let Str′ = löb(푆. Δ(퐴) × 푆) 퐴 general adjoint modalities is much more subtle. We will show and write 푧 and 푧 for pr (푧) and pr (푧) respectively: ℎ 푡 0 1  that by instantiating MTT with a particular mode theory we 퐴 퐵 퐶 ′ ′ ′ go : Δ( → → ) → Str퐴 → Str퐵 → Str퐶 can internally prove many properties of adjoint modalities 푓 푟. 휆푥,푦. 푓 푥 푦 , 푟 푥 푦 go( ) ≜ löb( ( ⊛훿 ℎ ⊛훿 ℎ modℓ ( ) ⊛ℓ 푡 ⊛ℓ 푡 )) that have previously been established only in special cases. zipWith : (퐴 → 퐵 → 퐶) → Str(퐴) → Str(퐵) → Str(퐶) To begin, we pick the walking adjunction [63] for our mode theory, i.e. the 2-category generated by Fig. 6. This mode zipWith(푓 ) ≜ 휆푥,푦. mod훾 (go(mod훿 (푓 ))) ⊛훾 푥 ⊛훾 푦 theory is the classifying 2-category for internal adjunctions: where ⊛휇 is defined in Section 3.1. coop every 2-functor Madj ≃ Madj → Cat determines a pair We can also use dependent types to reason about guarded of adjoint functors, and vice versa. Consequently, substitu- recursive programs. For example: tions Δ → Γ.µ휇 are in bijection with substitutions Δ.µ휈 → Γ. Theorem 6.4. If 푓 is commutative then zipWith(푓 ) is com- However, this is not enough on its own: we must also show mutative. That is, given 퐴, 퐵 : U and 푓 : 퐴 → 퐴 → 퐵 there is that ⟨휈 | −⟩ and ⟨휇 | −⟩ form an adjunction inside MTT. LICS ’20, July 8–11, 2020, Saarbrücken, Germany Daniel Gratzer, G. A. Kavvos, Andreas Nuyts, and Lars Birkedal

Recovering the adjunction in MTT. We can construct However, in order to construct this equivalence it will be the unit and counit internally: convenient to formulate an induction principle for ⟨휈 | B⟩. Supposing that Γ, µ ⊢ 퐶 : ⟨휈 | B⟩ → U @푚, we can unit : 퐴 → ⟨휇 | ⟨휈 | 퐴휂⟩⟩ counit : ⟨휈 | ⟨휇 | 퐴⟩⟩ → 퐴휖 휈◦휇 define a term 푥 푥휂 unit( ) ≜ mod휇 (mod휈 ( )) 휈 ⟨휈 ◦ 휇 | 퐶( ( ))⟩ → ⟨휈 ◦ 휇 | 퐶( ( ))⟩ 휖 if퐶 : mod휈 tt mod휈 ff counit(푥) ≜ let mod휈 (푦0) ← 푥 in let휈 mod휇 (푦1) ← 푦0 in 푦 1 → (푏 : ⟨휈 | B⟩) → 퐶휖 (푏) In order to account for dependence we must adjust the type 퐴 This is a version of the conditional that operates on ⟨휈 | B⟩ by a 2-cell. For example, in the definition of unit we assume rather than B. In fact, more is possible: in the technical report Γ ⊢ 퐴 type @푚, so ⟨휇 | ⟨휈 | 퐴⟩⟩ is ill-typed. We can, 1 we prove that if휈 can be constructed for any 퐶, not just small however, obtain a version of 퐴 that is typable in the context 휂 types. Using this stronger induction principle, we can show Γ, µ휇◦휈 by applying (−) to it, as in tm/var. We can prove that these two operations form an adjunc- Theorem 6.7. ⟨휈 | B⟩ ≃ B tion by showing they satisfy the triangle identities, e.g. We can similarly prove that 휈 preserves identity types. _ : (푥 : ⟨휈 | 퐴⟩) → Id⟨ | ⟩ (푥, counit(mod (unit) ⊛ 푥)) 휈 퐴 휈 휈 Theorem 6.8. There is a type-theoretic equivalence _ ≜ 휆푥. let mod휈 (푦) ← 푥 in refl(mod휈 (푦)) ⟨휈 | Id퐴 (푀, 푁 )⟩ ≃ Id⟨휈 |퐴⟩ (mod휈 (푀), mod휈 (푁 )) This proof relies on the fact that the modalities 휈 and 휇 satisfy M the triangle identities themselves in Madj. This instantiation of MTT with adj yields a systematic The existence of the unit and counit is enough to inter- treatment of an internal transposition axiom [42], and is suf- nally determine an adjunction. We might want to use an ficiently expressive to derive crisp induction principles [67]. alternative description, e.g. to manipulate a natural bijection In both cases we can use MTT instead of a handcrafted modal of hom-sets, Hom(퐿(퐴), 퐵)  Hom(퐴, 푅(퐵)). type theory. Note that we have not needed the addition of Unfortunately, this isomorphism cannot be recovered in- any new , so our canonicity result applies. ternally. First, notice that ⟨휈 | 퐴⟩ → 퐵 and 퐴 → ⟨휇 | 퐵⟩ 6.3 Further Examples are types in different modes—푛 and 푚 respectively—so (⟨휈 | 퐴⟩ → 퐵) ≃ (퐴 → ⟨휇 | 퐵⟩) is ill-typed. Second, even if In addition to the examples described above, we have applied 푛 = 푚 so that 휈 and 휇 are endomodalities and this equiv- MTT to a wide variety of other situations, including alence is well-typed, an internal equivalence is a stronger • parametricity, via degrees of relatedness [54], condition than a bijection of hom-sets: it is equivalent to an • synchronous and guarded programming with warps [33], isomorphism of exponential objects 퐵퐿(퐴)  푅(퐵)퐴. • finer grained notions of realizability and local maps of Prior work [42] addressed this by introducing a third categories of assemblies [13]. modality , such that terms of 퐴 represent global elements While interesting, we cannot discuss the details of these of 퐴, and2 then requiring transposition2 only for functions un- applications here for want of space. We invite the interested der . Global elements of 퐵퐴 are in bijection with Hom(퐴, 퐵), reader to consult the accompanying technical report. so the2 postulated equivalence corresponds to the expected bijection. We can rephrase this argument in MTT. Suppose 7 Related Work 푛 푚 푚,푚 that = , and that Hom( ) is equipped with an ini- MTT is related to many prior modal type theories. In partic- 휏 푚 푚 tial object, i.e. a modality : → and a unique 2-cell ular, its formulation draws on three important techniques: 휏 휉 휉 !: → for all . Then, split contexts, left division, and the Fitch style. Theorem 6.5. The following equivalence is definable in MTT: Split-context type theories [26, 27, 39, 52, 58, 59, 67, 71] di- ⟨휏 | ⟨휈 | 퐴!⟩ → 퐵⟩ ≃ ⟨휏 | 퐴 → ⟨휇 | 퐵!⟩⟩. vide the context into different zones—one for each modality— which are then manipulated by modal connectives. This has In fact, because modalities in MTT preserve finite products proven to be an effective approach for a number of modali- (a consequence of ⊛휈 ), an alternative phrasing of transposi- ties, and sometimes even scales to full dependent type theo- tion is possible. ries [27, 67, 71]. However, the structure of contexts becomes very complex as the number of modalities increases. Theorem 6.6. The following equivalence is definable in MTT: In order to manage this complexity, some modal type the- ⟨휇 | ⟨휈 | 퐴휂⟩ → 퐵⟩ ≃ 퐴 → ⟨휇 | 퐵⟩. ories employ left-division: each variable declaration in the Crisp induction for the left adjoint. Many classical re- context is annotated with a modality, and a left-division op- sults about adjunctions can be replayed inside MTT. For eration, which is a left adjoint to post-composition of modal- instance, by carrying out a proof that left adjoints preserve ities,4 is used to state the introduction rules [1–3, 54, 55, 57]. colimits we recover modal or crisp induction principles for the 4Since composition may be understood as a multiplication operation, this left adjoint 휈 [43, 67]. We can then show e.g. that ⟨휈 | B⟩ ≃ B. left adjoint behaves like division: 휇 ≤ 휈휉 ⇐⇒ 휈\휇 ≤ 휉. Multimodal Dependent Type Theory LICS ’20, July 8–11, 2020, Saarbrücken, Germany

Left-division calculi handle multiple modalities and support similar to that discussed in Section 5.1 by gluing along the full dependent types, but many important modal situations appropriate nerves. The latter result would pave the way to cannot be equipped with a left-division structure. a practical implementation of a multimodal . Another technique stipulates that modalities are essen- Presently MTT only supports modalities which behave tially right adjoints, with the corresponding left adjoints like right adjoints. While this covers a wide class of exam- being constructors on contexts. These Fitch-style type theo- ples, many modalities are instead left adjoints. We hope to ries [10, 11, 14, 20, 30] are relatively simple, which has made extend MTT to allow left adjoints to act on types instead of them convenient for programming applications [11, 30]. Nev- merely contexts while retaining its practical syntax. Simi- ertheless, scaling this approach to a multimodal setting has larly, we also hope to extend our analysis to some class of proven difficult. In particular, extending the original elimina- modality-specific operations, e.g. Löb induction. These oper- tion rule to a multimodal setting remains an open problem. ations cannot be captured by a mode theory, and so can only MTT synthesizes these approaches by including both Fitch- be added axiomatically to MTT (as was done in Section 6.1), style locks and left-division-style annotations in its judgmen- thus invalidating some of our metatheorems. However, such tal structure. The combination of these devices circumvents operations play an important role in many applications, and many previously encountered difficulties. For example, this should be accounted for in a systematic way. combination obviates the need for a left division operation, as MTT uses a Fitch-style introduction rule. On the other hand, Acknowledgments the left-division-style elimination rule of MTT smoothly accommodates multiple interacting modalities. We are grateful for productive conversations with Carlo Most prior work on modal type theory has focused on Angiuli, Dominique Devriese, Adrien Guatto, Magnus Baun- incorporating a specific collection of modalities. The sole sgaard Kristensen, Daniel Licata, Rasmus Ejlers Møgelberg, exception is the LSR framework of Licata et al. [44]. The LSR Matthieu Sozeau, Jonathan Sterling, and Andrea Vezzosi. framework supports an arbitrary collection of substructural Alex Kavvos was supported in part by a research grant modalities over simple types, and there is ongoing work on a (12386, Guarded Type Theory) from the VILLUM dependently-typed system. The price to pay for this expres- Foundation. Andreas Nuyts holds a PhD Fellowship from sivity is practicality: the modal connectives require delayed the Research Foundation - Flanders (FWO). This work was substitutions [12, 16], which complicate the equational the- supported in part by a Villum Investigator grant (no. 25804), ory, and make pen-and-paper calculations cumbersome. The Center for Basic Research in Program Verification (CPV), relationship between the modalities of MTT and those of the from the VILLUM Foundation. LSR framework is not clear. The introduction rule tm/modal- intro mirrors the introduction rule for 푈 types. This is to be References 푈 expected, as types behave like right adjoints. On the other [1] Andreas Abel. 2006. A Polymorphic Lambda-Calculus with Sized Higher- hand, the elimination rule tm/modal-elim/single-modality Order Types. Ph.D. Dissertation. Ludwig-Maximilians-Universität does not match the rule for 푈 types, but instead is closer to München. the elimination rule for 퐹 types. In fact, this is a necessary [2] Andreas Abel. 2008. Polarised for sized types. Mathematical compromise to avoid the introduction of delayed substitu- Structures in Computer Science 18, 5 (2008), 797–822. https://doi.org/ 푈 10.1017/S0960129508006853 tions. In op. cit. the elimination rule for types and the [3] Andreas Abel and Gabriel Scherer. 2012. On Irrelevance and Algorith- introduction rule for 퐹 types both require annotation with a mic Equality in Predicative Type Theory. Logical Methods in Computer substitution to bring the context into a specific shape. MTT Science 8, 1 (2012). https://doi.org/10.2168/LMCS-8(1:29)2012 avoids this by by mixing these two styles of presentation. [4] Stuart Frazier Allen. 1987. A non-type-theoretic semantics for type- theoretic language. Ph.D. Dissertation. Cornell University. [5] Thorsten Altenkirch and Ambrus Kaposi. 2016. Normalisation by 8 Conclusions & Future Work Evaluation for Dependent Types. In 1st International Conference on Formal Structures for Computation and Deduction (FSCD 2016) (Leibniz We introduced and studied MTT, a dependent type theory International Proceedings in Informatics (LIPIcs)), Delia Kesner and parametrized by a mode theory that describes interacting Brigitte Pientka (Eds.), Vol. 52. Schloss Dagstuhl–Leibniz-Zentrum modalities. We have demonstrated that MTT may be used to fuer Informatik, Dagstuhl, Germany, 6:1–6:16. https://doi.org/10.4230/ LIPIcs.FSCD.2016.6 reason about several important modal settings, and proven [6] Carlo Angiuli. 2019. Computational Semantics of Cartesian Cubical basic metatheorems about its syntax, including canonicity. Type Theory. Ph.D. Dissertation. Carnegie Mellon University. In the future we plan to further develop the metatheory [7] Carlo Angiuli, Kuen-Bang Hou (Favonia), and Robert Harper. 2018. of MTT. In addition to extending our canonicity result to Cartesian Cubical Computational Type Theory: Constructive Reason- remove the restriction that locks preserve the empty context, ing with Paths and Equalities. In 27th EACSL Annual Conference on Computer Science Logic (CSL 2018) (Leibniz International Proceedings we hope to prove that MTT enjoys normalization, and hence in Informatics (LIPIcs)), Dan Ghica and Achim Jung (Eds.), Vol. 119. that type-checking is decidable (provided the mode theory is). Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Ger- Both of these theorems can be proven by gluing arguments many, 6:1–6:17. https://doi.org/10.4230/LIPIcs.CSL.2018.6 LICS ’20, July 8–11, 2020, Saarbrücken, Germany Daniel Gratzer, G. A. Kavvos, Andreas Nuyts, and Lars Birkedal

[8] Robert Atkey and Conor McBride. 2013. Productive Coprogramming [25] P.-L. Curien. 1990. Substitution up to isomorphism. Diagrammes 23 with Guarded Recursion. In Proceedings of the 18th ACM SIGPLAN (1990), 43–66. http://www.numdam.org/item/DIA_1990__23__43_0 International Conference on (ICFP ’13). Asso- [26] Rowan Davies and Frank Pfenning. 2001. A Modal Analysis of Staged ciation for Computing Machinery, 197–208. https://doi.org/10.1145/ Computation. J. ACM 48, 3 (May 2001), 555–604. 2500365.2500597 [27] Valeria de Paiva and Eike Ritter. 2015. Fibrational Modal Type Theory, [9] Steve Awodey. 2018. Natural models of . In Proceedings of the Tenth Workshop on Logical and Semantic Frame- Mathematical Structures in Computer Science 28, 2 (2018), 241–286. works, with Applications (LSFA 2015). Electronic Notes in Theoretical https://doi.org/10.1017/S0960129516000268 arXiv:1406.3219 Computer Science. https://doi.org/10.1016/j.entcs.2016.06.010 [10] Patrick Bahr, Hans Bugge Grathwohl, and Rasmus Ejlers Møgelberg. [28] Peter Dybjer. 1996. Internal type theory. In Types for Proofs and Pro- 2017. The clocks are ticking: No more delays!. In 2017 32nd Annual grams, Stefano Berardi and Mario Coppo (Eds.). Springer Berlin Hei- ACM/IEEE Symposium on Logic in Computer Science (LICS). IEEE. https: delberg, Berlin, Heidelberg, 120–134. https://doi.org/10.1007/3-540- //doi.org/10.1109/LICS.2017.8005097 61780-9_66 [11] Patrick Bahr, Christian Uldal Graulund, and Rasmus Ejlers Møgelberg. [29] Johan Georg Granström and Johan Georg Granström. 2011. Treatise 2019. Simply RaTT: A Fitch-style Modal Calculus for Reactive Program- on Intuitionistic Type Theory. Springer Netherlands. https://doi.org/ ming Without Space Leaks. Proc. ACM Program. Lang. 3, Article 109 10.1007/978-94-007-1736-7 (2019), 109:1–109:27 pages. Issue ICFP. https://doi.org/10.1145/3341713 [30] Daniel Gratzer, Jonathan Sterling, and Lars Birkedal. 2019. Implement- [12] G. M. Bierman and V. C. V. de Paiva. 2000. On an Intuitionistic ing a Modal Dependent Type Theory. Proc. ACM Program. Lang. 3 . Studia Logica 65, 3 (2000). https://doi.org/10.1023/A: (2019). Issue ICFP. https://doi.org/10.1145/3341711 1005291931660 [31] Daniel Gratzer, Jonathan Sterling, and Lars Birkedal. 2019. [13] Lars Birkedal. 2000. Developing Theories of Types and Computability Normalization-by-Evaluation for Modal Dependent Type The- via Realizability. Electronic Notes in Theoretical Computer Science 34 ory. https://jozefg.github.io/papers/2019-implementing-modal- (2000). dependent-type-theory-tech-report.pdf Technical Report for the [14] Lars Birkedal, Ranald Clouston, Bassel Mannaa, Rasmus Ejlers Møgel- ICFP paper by the same name. berg, Andrew M. Pitts, and Bas Spitters. 2020. Modal dependent [32] Jacob A Gross, Daniel R Licata, Max S New, Jennifer Paykin, Mitchell type theory and dependent right adjoints. Mathematical Structures Riley, Michael Shulman, and Felix Wellen. 2017. Differential Co- in Computer Science 30, 2 (2020), 118–138. https://doi.org/10.1017/ hesive Type Theory (Extended Abstract). In Extended abstracts for S0960129519000197 arXiv:1804.05236 the Workshop "Homotopy Type Theory and ". [15] Lars Birkedal, Rasmus Møgelberg, Jan Schwinghammer, and Kristian https://hott-uf.github.io/2017/abstracts/cohesivett.pdf Støvring. 2012. First steps in synthetic guarded domain theory: step- [33] Adrien Guatto. 2018. A Generalized Modality for Recursion. In Pro- indexing in the topos of trees. Logical Methods in Computer Science 8, ceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer 4 (2012). https://doi.org/10.2168/LMCS-8(4:1)2012 Science (LICS ’18). ACM. https://doi.org/10.1145/3209108.3209148 [16] Aleš Bizjak, Hans Bugge Grathwohl, Ranald Clouston, Rasmus E. [34] Martin Hofmann. 1997. Syntax and Semantics of Dependent Types. In Møgelberg, and Lars Birkedal. 2016. Guarded Dependent Type Theory Semantics and Logics of Computation, Andrew M. Pitts and P. Dybjer with Coinductive Types. In Foundations of Software Science and Com- (Eds.). Cambridge University Press, 79–130. https://doi.org/10.1017/ putation Structures, Bart Jacobs and Christof Löding (Eds.). Springer CBO9780511526619.004 Berlin Heidelberg, 20–35. [35] Simon Huber. 2019. Canonicity for Cubical Type Theory. Journal [17] Aleš Bizjak and Rasmus Ejlers Møgelberg. 2015. A Model of Guarded Automated Reasoning 63, 2 (2019), 173–210. https://doi.org/10.1007/ Recursion With Clock Synchronisation. Electronic Notes in Theoretical s10817-018-9469-1 Computer Science 319 (2015), 83 – 101. https://doi.org/10.1016/j.entcs. [36] B. Jacobs. 1999. and Type Theory. Number 141 in 2015.12.007 The 31st Conference on the Mathematical Foundations of Studies in Logic and the Foundations of Mathematics. North Holland. Programming Semantics (MFPS XXXI). [37] Ambrus Kaposi, Simon Huber, and Christian Sattler. 2019. Gluing [18] John Cartmell. 1978. Generalised Algebraic Theories and Contextual for type theory. In Proceedings of the 4th International Conference on Categories. Ph.D. Dissertation. University of Oxford. Formal Structures for Computation and Deduction (FSCD 2019), Herman [19] Simon Castellan, Pierre Clairambault, and Peter Dybjer. 2017. Un- Geuvers (Ed.), Vol. 131. decidability of Equality in the Free Locally Cartesian Closed Cat- [38] Ambrus Kaposi, András Kovács, and Thorsten Altenkirch. 2019. Con- egory. Logical Methods in Computer Science 13, 4 (2017). https: structing Quotient Inductive-inductive Types. Proc. ACM Program. //doi.org/10.23638/LMCS-13(4:22)2017 Lang. 3, POPL, Article 2 (Jan. 2019), 24 pages. https://doi.org/10.1145/ [20] Ranald Clouston. 2018. Fitch-Style Modal Lambda Calculi. In Foun- 3290315 dations of Software Science and Computation Structures, Christel Baier [39] G. A. Kavvos. 2017. Dual-context calculi for modal logic. In 2017 32nd and Ugo Dal Lago (Eds.). Springer International Publishing, 258–275. Annual ACM/IEEE Symposium on Logic in Computer Science (LICS). [21] Ranald Clouston, Aleš Bizjak, Hans Bugge Grathwohl, and Lars 1–12. https://doi.org/10.1109/LICS.2017.8005089 arXiv:1602.04860 Birkedal. 2015. Programming and Reasoning with Guarded Recursion [40] G. A. Kavvos. 2019. Modalities, Cohesion, and Information Flow. for Coinductive Types. In Foundations of Software Science and Com- Proceedings of the ACM on Programming Languages 3 (2019), 20:1– putation Structures (Berlin, Heidelberg), Andrew Pitts (Ed.). Springer 20:29. Issue POPL. https://doi.org/10.1145/3290333 Berlin Heidelberg, 407–421. [41] F. William Lawvere. 2007. Axiomatic cohesion. Theory and Applications [22] Thierry Coquand. 1986. An Analysis of Girard’s Paradox. In Pro- of Categories 19, 3 (2007), 41–49. http://www.tac.mta.ca/tac/volumes/ ceedings of the First Annual IEEE Symposium on Logic in Computer 19/3/19-03.pdf Science (LICS 1986) (Cambridge, MA, USA). IEEE Computer Society [42] Daniel R. Licata, Ian Orton, Andrew M. Pitts, and Bas Spitters. 2018. Press, 227–236. Internal Universes in Models of Homotopy Type Theory. In 3rd In- [23] Thierry Coquand. 2013. Presheaf model of type theory. http://www. ternational Conference on Formal Structures for Computation and De- cse.chalmers.se/~coquand/presheaf.pdf duction (FSCD 2018) (Leibniz International Proceedings in Informatics [24] Thierry Coquand. 2018. Canonicity and normalization for Dependent (LIPIcs)), H. Kirchner (Ed.). Schloss Dagstuhl-Leibniz-Zentrum fuer Type Theory. arXiv:1810.09367 Informatik, 22:1–22:17. https://doi.org/10.4230/LIPIcs.FSCD.2018.22 arXiv:1801.07664 Multimodal Dependent Type Theory LICS ’20, July 8–11, 2020, Saarbrücken, Germany

[43] Daniel R. Licata and Michael Shulman. 2016. Adjoint Logic with a 2- [60] Dag Prawitz. 1965. : a proof-theoretical study. Category of Modes. In Logical Foundations of Computer Science, Sergei Almquist and Wiksell. Artemov and Anil Nerode (Eds.). Springer International Publishing, [61] Jason Reed. 2009. A Judgmental Deconstruction of Modal Logic. (2009). 219–235. https://doi.org/10.1007/978-3-319-27683-0_16 http://www.cs.cmu.edu/~jcreed/papers/jdml.pdf [44] Daniel R. Licata, Michael Shulman, and Mitchell Riley. 2017. A Fibra- [62] Egbert Rijke, Michael Shulman, and Bas Spitters. 2020. Modalities tional Framework for Substructural and Modal Logics. In 2nd Interna- in homotopy type theory. Logical Methods in Computer Science 16, 1 tional Conference on Formal Structures for Computation and Deduction (2020). arXiv:1706.07526 (FSCD 2017) (Leibniz International Proceedings in Informatics (LIPIcs)), [63] Stephen Schanuel and Ross Street. 1986. The free adjunction. Cahiers Dale Miller (Ed.), Vol. 84. Schloss Dagstuhl–Leibniz-Zentrum fuer de Topologie et Géométrie Différentielle Catégoriques 27, 1 (1986), 81–83. Informatik, 25:1–25:22. https://doi.org/10.4230/LIPIcs.FSCD.2017.25 http://www.numdam.org/item/CTGDC_1986__27_1_81_0 [45] Zhaohui Luo. 2012. Notes on Universes in Type Theory. http: [64] Urs Schreiber. 2013. Differential cohomology in a cohesive infinity- //www.dcs.rhul.ac.uk/home/zhaohui/universes.pdf Notes for a talk at topos. (2013). arXiv:1310.7930 Institute for Advanced Study in Princeton in Oct 2012. [65] Urs Schreiber and Michael Shulman. 2012. Quantum Gauge Field [46] Per Martin-Löf. 1975. An intuitionistic theory of types: predicative Theory in Cohesive Homotopy Type Theory. In Proceedings 9th Work- part. In Logic Colloquium ’73, Proceedings of the Logic Colloquium, H.E. shop on Quantum Physics and Logic, QPL 2012, Brussels, Belgium, 10-12 Rose and J.C. Shepherdson (Eds.). Studies in Logic and the Foundations October 2012 (EPTCS), Ross Duncan and Prakash Panangaden (Eds.), of Mathematics, Vol. 80. North-Holland, 73–118. Vol. 158. 109–126. https://doi.org/10.4204/EPTCS.158.8 [47] Per Martin-Löf. 1992. Substitution calculus. Notes from a lecture [66] Michael Shulman. 2015. Univalence for inverse diagrams and ho- given in Göteborg. motopy canonicity. Mathematical Structures in Computer Science [48] Conor McBride and Ross Paterson. 2008. Applicative programming 25, 5 (2015), 1203–1277. https://doi.org/10.1017/S0960129514000565 with effects. Journal of Functional Programming 18, 1 (2008). https: arXiv:1203.3253 //doi.org/10.1017/S0956796807006326 [67] Michael Shulman. 2018. Brouwer’s fixed-point theorem in real- [49] John C. Mitchell and Andre Scedrov. 1993. Notes on sconing and cohesive homotopy type theory. Mathematical Structures in Com- relators. In Computer Science Logic, E. Börger, G. Jäger, H. Kleine Bün- puter Science 28, 6 (2018), 856–941. https://doi.org/10.1017/ ing, S. Martini, and M. M. Richter (Eds.). Springer Berlin Heidelberg, S0960129517000147 352–378. https://doi.org/10.1007/3-540-56992-8_21 [68] Jonathan Sterling. 2019. Algebraic Type Theory and Universe Hierar- [50] Rasmus Ejlers Møgelberg. 2014. A Type Theory for Productive Co- chies. (2019). arXiv:1902.08848 programming via Guarded Recursion. In Proceedings of the Joint Meet- [69] W. W. Tait. 1967. Intensional Interpretations of Functionals of Finite ing of the Twenty-Third EACSL Annual Conference on Computer Sci- Type I. Journal of Symbolic Logic 32, 2 (1967), 198–212. https://doi. ence Logic (CSL) and the Twenty-Ninth Annual ACM/IEEE Sympo- org/10.2307/2271658 sium on Logic in Computer Science (LICS) (CSL-LICS ’14). https: [70] The Univalent Foundations Program. 2013. Homotopy Type Theory: //doi.org/10.1145/2603088.2603132 Univalent Foundations of Mathematics. Institute for Advanced Study. [51] H. Nakano. 2000. A modality for recursion. In Proceedings Fifteenth An- https://homotopytypetheory.org/book nual IEEE Symposium on Logic in Computer Science (Cat. No.99CB36332). [71] Colin Zwanziger. 2019. Natural Model Semantics for Comonadic and IEEE Computer Society, 255–266. Adjoint Type Theory: Extended Abstract. In Preproceedings of Applied [52] Aleksandar Nanevski, Frank Pfenning, and Brigitte Pientka. 2008. Con- Conference 2019. textual Modal Type Theory. ACM Transactions on Computational Logic 9, 3 (2008). https://doi.org/10.1145/1352582.1352591 [53] Andreas Nuyts. 2018. Presheaf Models of Relational Modalities in Dependent Type Theory. arXiv:1805.08684 [54] Andreas Nuyts and Dominique Devriese. 2018. Degrees of Relatedness: A Unified Framework for Parametricity, Irrelevance, Ad Hoc Polymor- phism, Intersections, Unions and Algebra in Dependent Type Theory. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science (LICS ’18). ACM. https://doi.org/10.1145/3209108. 3209119 [55] Andreas Nuyts, Andrea Vezzosi, and Dominique Devriese. 2017. Para- metric Quantifiers for Dependent Type Theory. Proc. ACM Program. Lang. 1, ICFP (2017). https://doi.org/10.1145/3110276 [56] Erik Palmgren. 1998. On universes in type theory. In Twenty Five Years of Constructive Type Theory, G. Sambin and J. Smith (Eds.). Oxford Uni- versity Press, 191–204. http://www2.math.uu.se/~palmgren/universe. pdf [57] F. Pfenning. 2001. Intensionality, , and proof irrelevance in modal type theory. In Proceedings 16th Annual IEEE Symposium on Logic in Computer Science. IEEE, 221–230. https://doi.org/10.1109/ LICS.2001.932499 [58] Frank Pfenning and Rowan Davies. 2001. A Judgmental Reconstruction of Modal Logic. Mathematical Structures in Computer Science 11, 4 (2001), 511–540. https://doi.org/10.1017/S0960129501003322 [59] Brigitte Pientka, Andreas Abel, Francisco Ferreira, David Thibodeau, and Rébecca Zucchini. 2019. A Type Theory for Defining Logics and Proofs. In Proceedings of the 34th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS).