Reference. Denotational Semantics of Gradual Typing using Synthetic Guarded Domain Theory
Gradually typed programming languages, which allow for soundly mixing static and dynamically typed programming styles, present a strong challenge for metatheorists. Even the simplest sound gradually typed languages feature at least recursion and errors, with realistic languages featuring furthermore runtime allocation of memory locations and dynamic type tags. Further, the desired metatheoretic properties of gradually typed languages have become increasingly sophisticated: validity of type-based equational reasoning as well as the relational property known as graduality. Many recent works have tackled verifying these properties, but the resulting mathematical developments are highly repetitive and tedious, with few reusable theorems persisting across different developments.
In this work, we present a new denotational semantics for gradual typing developed using guarded domain theory. Guarded domain theory combines the generality of step-indexed logical relations for modeling advanced programming features with the modularity and reusability of denotational semantics. We demonstrate the feasibility of this approach with a model of a simple gradually typed lambda calculus and prove the validity of beta-eta equality and the graduality theorem for the denotational model. This model should provide the basis for a reusable mathematical theory of gradually typed program semantics. Finally, we have mechanized most of the core theorems of our development in Guarded Cubical Agda, a recent extension of Agda with support for the guarded recursive constructions we use.
Cite
Cited by (1)
Modelling Recursion and Probabilistic Choice in Guarded Type Theory stassen-2025-modelling
Cites 43 works (10 here)
With notes (10)
Modelling Recursion and Probabilistic Choice in Guarded Type Theory stassen-2025-modelling
Modular Denotational Semantics for Effects with Guarded Interaction Trees frumin-2024-modular
Gradual Typing for Effect Handlers new_giovannini_licata_2023
We present a gradually typed language, GrEff, with effects and handlers that supports migration from unchecked to checked effect typing. This serves as a simple model of the integration of an effect typing discipline with an existing effectful typed language that does not track fine-grained effect information. Our language supports a simple module system to model the programming model of gradual migration from unchecked to checked effect typing in the style of Typed Racket.
The surface language GrEff is given semantics by elaboration to a core language Core GrEff. We equip Core GrEff with an inequational theory for reasoning about the semantic error ordering and desired program equivalences for programming with effects and handlers. We derive an operational semantics for the language from the equations provable in the theory. We then show that the theory is sound by constructing an operational logical relations model to prove the graduality theorem. This extends prior work on embedding-projection pair models of gradual typing to handle effect typing and subtyping.
Graduality and Parametricity: Together Again for the First Time new_jamner_ahmed_2020
Parametric polymorphism and gradual typing have proven to be a difficult combination, with no language yet produced that satisfies the fundamental theorems of each: parametricity and graduality. Notably, Toro, Labrada, and Tanter (POPL 2019) conjecture that for any gradual extension of System F that uses dynamic type generation, graduality and parametricity are “simply incompatible”. However, we argue that it is not graduality and parametricity that are incompatible per se, but instead that combining the syntax of System F with dynamic type generation as in previous work necessitates type-directed computation, which we show has been a common source of graduality and parametricity violations in previous work.
We then show that by modifying the syntax of universal and existential types to make the type name generation explicit, we remove the need for type-directed computation, and get a language that satisfies both graduality and parametricity theorems. The language has a simple runtime semantics, which can be explained by translation to a statically typed language where the dynamic type is interpreted as a dynamically extensible sum type. Far from being in conflict, we show that the parametricity theorem follows as a direct corollary of a relational interpretation of the graduality property.
Call-by-name Gradual Type Theory new_licata_2020_lmcs
Gradual Type Theory new_licata_ahmed_2019
Gradually typed languages are designed to support both dynamically typed and statically typed programming styles while preserving the benefits of each. While existing gradual type soundness theorems for these languages aim to show that type-based reasoning is preserved when moving from the fully static setting to a gradual one, these theorems do not imply that correctness of type-based refactorings and optimizations is preserved. Establishing correctness of program transformations is technically difficult, because it requires reasoning about program equivalence, and is often neglected in the metatheory of gradual languages.
In this paper, we propose an axiomatic account of program equivalence in a gradual cast calculus, which we formalize in a logic we call gradual type theory (GTT). Based on Levy’s call-by-push-value, GTT gives an axiomatic account of both call-by-value and call-by-name gradual languages. Based on our axiomatic account we prove many theorems that justify optimizations and refactorings in gradually typed languages. For example, uniqueness principles for gradual type connectives show that if the βη laws hold for a connective, then casts between that connective must be equivalent to the so-called “lazy” cast semantics. Contrapositively, this shows that “eager” cast semantics violates the extensionality of function types. As another example, we show that gradual upcasts are pure functions and, dually, gradual downcasts are strict functions. We show the consistency and applicability of our axiomatic theory by proving that a contract-based implementation using the lazy cast semantics gives a logical relations model of our type theory, where equivalence in GTT implies contextual equivalence of the programs. Since GTT also axiomatizes the dynamic gradual guarantee, our model also establishes this central theorem of gradual typing. The model is parametrized by the implementation of the dynamic types, and so gives a family of implementations that validate type-based optimization and the gradual guarantee.
Graduality from Embedding-Projection Pairs new_ahmed_2018
Gradually typed languages allow statically typed and dynamically typed code to interact while maintaining benefits of both styles. The key to reasoning about these mixed programs is Siek-Vitousek-Cimini-Boyland’s (dynamic) gradual guarantee, which says that giving components of a program more precise types only adds runtime type checking, and does not otherwise change behavior. In this paper, we give a semantic reformulation of the gradual guarantee called graduality. We change the name to promote the analogy that graduality is to gradual typing what parametricity is to polymorphism. Each gives a local-to-global, syntactic-to-semantic reasoning principle that is formulated in terms of a kind of observational approximation.
Utilizing the analogy, we develop a novel logical relation for proving graduality. We show that embedding-projection pairs (ep pairs) are to graduality what relations are to parametricity. We argue that casts between two types where one is “more dynamic” (less precise) than the other necessarily form an ep pair, and we use this to cleanly prove the graduality cases for casts from the ep-pair property. To construct ep pairs, we give an analysis of the type dynamism relation—also known as type precision or naïve subtyping—that interprets the rules for type dynamism as compositional constructions on ep pairs, analogous to the coercion interpretation of subtyping.
Call-by-name Gradual Type Theory new_licata_2018_fscd
Productive coprogramming with guarded recursion atkey-2013-productive
Framed bicategories and monoidal fibrations shulman_2008
In some bicategories, the 1-cells are ‘morphisms’ between the 0-cells, such as functors between categories, but in others they are ‘objects’ over the 0-cells, such as bimodules, spans, distributors, or parametrized spectra. Many bicategorical notions do not work well in these cases, because the ‘morphisms between 0-cells’, such as ring homomorphisms, are missing. We can include them by using a pseudo double category, but usually these morphisms also induce base change functors acting on the 1-cells. We avoid complicated coherence problems by describing base change ‘nonalgebraically’, using categorical fibrations. The resulting ‘framed bicategories’ assemble into 2-categories, with attendant notions of equivalence, adjunction, and so on which are more appropriate for our examples than are the usual bicategorical ones.
We then describe two ways to construct framed bicategories. One is an analogue of rings and bimodules which starts from one framed bicategory and builds another. The other starts from a ‘monoidal fibration’, meaning a parametrized family of monoidal categories, and produces an analogue of the framed bicategory of spans. Combining the two, we obtain a construction which includes both enriched and internal categories as special cases.
External (33)
- Agda Formalization for "Denotational Semantics of Gradual Typing using Synthetic Guarded Domain Theory" (2024)
- Denotational Semantics of Gradual Typing using Synthetic Guarded Domain Theory (Extended Version) (2024)
- On the design of a gradual dependently typed language for programming (Eremondi, PhD dissertation, UBC) (2023)
- Greatest HITs: Higher inductive types in coinductive definitions via induction under clocks (2022)
- Deep and shallow types for gradual languages (2022)
- Gradualizing the Calculus of Inductive Constructions (2022)
- Denotational semantics of general store and polymorphism (2022)
- Parameterized cast calculi and reusable meta-theory for gradually typed lambda calculi (2021)
- Formalizing 𝜋-calculus in guarded cubical Agda (2020)
- Bisimulation as path type for guarded recursive types (2019)
- The clocks are ticking: No more delays! (2017)
- The gradualizer: a methodology and algorithm for generating gradual type systems (2016)
- Abstracting gradual typing (2016)
- Denotational semantics of recursive types in synthetic guarded domain theory (2016)
- Big types in little runtime: open-world soundness and collaborative blame for gradual type systems (2016)
- Cubical Type Theory: A Constructive Interpretation of the Univalence Axiom (2015)
- Refined Criteria for Gradual Typing (2015)
- First Steps in Synthetic Guarded Domain Theory: Step-Indexing in the Topos of Trees (2011)
- Space-efficient gradual typing (2010)
- Realizability Semantics of Parametric Polymorphism, General References, and Recursive Types (2009)
- Non-parametric parametricity (2009)
- The design and implementation of typed scheme (2008)
- Step-Indexed Syntactic Logical Relations for Recursive and Quantified Types (2006)
- Interlanguage migration (2006)
- Gradual Typing for Functional Languages (Siek, Taha; Scheme Workshop) (2006)
- General Recursion via Coinductive Types (2005)
- Adjunction Models For Call-By-Push-Value With Stacks (2003)
- Parametricity As a Notion of Uniformity in Reflexive Graphs (2002)
- An indexed model of recursive types for foundational proof-carrying code (2001)
- A modality for recursion (2000)
- Call-by-Push-Value: A Subsuming Paradigm (1999)
- Notions of computation and monads (1991)
- Computational lambda-calculus and monads (1989)