Gradual Type Theory (Extended Version)

11/06/2018
by   Max S. New, et al.
0

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, 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. We then prove 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 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 and dually, gradual downcasts are strict. We show the consistency and applicability of our theory by proving that an 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.

READ FULL TEXT
research
06/19/2018

Reasoning about Polymorphic Manifest Contracts

Manifest contract calculi, which integrate cast-based dynamic contract c...
research
07/08/2018

Graduality from Embedding-projection Pairs (Extended Version)

Gradually typed languages allow statically typed and dynamically typed c...
research
02/16/2022

Galois connecting call-by-value and call-by-name

We establish a general framework for reasoning about the relationship be...
research
11/02/2021

Do Names Echo Semantics? A Large-Scale Study of Identifiers Used in C++'s Named Casts

Developers relax restrictions on a type to reuse methods with other type...
research
07/31/2023

Free theorems from univalent reference types

We develop a denotational semantics for general reference types in an im...
research
03/05/2021

Modal Reasoning = Metric Reasoning, via Lawvere

Graded modal types systems and coeffects are becoming a standard formali...
research
01/30/2020

Toward a Mechanized Compendium of Gradual Typing

The research on gradual typing has grown considerably over the last deca...

Please sign up or login with your details

Forgot password? Click here to reset