Abstract

AbstractGradually typed languages are designed to support both dynamically typed and statically typed programming styles while preserving the benefits of each. Sound gradually typed languages dynamically check types at runtime at the boundary between statically typed and dynamically typed modules. However, there is much disagreement in the gradual typing literature over how to enforce complex types such as tuples, lists, functions and objects. In this paper, we propose a new perspective on the design of runtime gradual type enforcement: runtime type casts exist precisely to ensure the correctness of certain type-based refactorings and optimizations. For instance, for simple types, a language designer might desire that beta-eta equality is valid. We show that this perspective is useful by demonstrating that a cast semantics can be derived from beta-eta equality. We do this by providing an axiomatic account program equivalence in a gradual cast calculus in a logic we callgradual type theory(GTT). Based on Levy’s call-by-push-value, GTT allows us to axiomatize both call-by-value and call-by-name gradual languages. We then show that we can derive the behavior of casts for simple types from the corresponding eta equality principle and the assumption that the language satisfies a property calledgraduality, also known as the dynamic gradual guarantee. Since we can derive the semantics from the assumption of eta equality, we also receive a useful contrapositive: any observably different cast semantics that satisfies gradualitymustviolate the eta equality. 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 parameterized by the implementation of the dynamic types, and so gives a family of implementations that validate type-based optimization and the gradual guarantee.

Highlights

  • Typed languages (Siek & Taha, 2006; Tobin-Hochstadt & Felleisen, 2008) are designed to support the gradual migration from dynamically typed to statically typed programming with a unified syntax and implementation

  • We systematically study the relationship between casts and equational reasoning principles by working with an axiomatic theory of gradual program equivalence, a language and logic we call gradual type theory (GTT)

  • We develop an axiomatic gradual type theory GTT for a unified language that includes both call-by-value/eager types and call-by-name/lazy types (Sections 2, 3), and show that it is sound for contextual equivalence via a logical relations model (Sections 5, 6, 7)

Read more

Summary

Introduction

Typed languages (Siek & Taha, 2006; Tobin-Hochstadt & Felleisen, 2008) are designed to support the gradual migration from dynamically typed to statically typed programming with a unified syntax and implementation This is based on the hypothesis that. Typed programs, on the other hand, are checked at compile time for internal consistency, detecting errors before the program even runs and providing mathematically sound reasoning principles that simplify correctness arguments, justify type-based refactorings, enable compiler optimizations and underlie formal software verification. This make statically typed languages ideal for long-term program maintenance and reusable libraries. The value types include eager products 1 and A1 × A2 and sums 0 and A1 + A2, which behave as in a call-by-value/eager language

Objectives
Results
Conclusion
Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call