Abstract
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.
Supplemental Material
- Danel Ahman, Neil Ghani, and Gordon D. Plotkin. 2016. Dependent Types and Fibred Computational Effects. In Foundations of Software Science and Computation Structures. 36–54.Google Scholar
- Amal Ahmed. 2006. Step-Indexed Syntactic Logical Relations for Recursive and Quantified Types. In European Symposium on Programming (ESOP). 69–83. Google Scholar
Digital Library
- Amal Ahmed, Derek Dreyer, and Andreas Rossberg. 2009. State-Dependent Representation Independence. In ACM Symposium on Principles of Programming Languages (POPL), Savannah, Georgia. Google Scholar
Digital Library
- Amal Ahmed, Dustin Jamner, Jeremy G. Siek, and Philip Wadler. 2017. Theorems for Free for Free: Parametricity, With and Without Types. In International Conference on Functional Programming (ICFP), Oxford, United Kingdom.Google Scholar
- Andrej Bauer and Matija Pretnar. 2013. An Effect System for Algebraic Effects and Handlers. In Algebra and Coalgebra in Computer Science. Springer Berlin Heidelberg, Berlin, Heidelberg, 1–16.Google Scholar
- Matteo Cimini and Jeremy G. Siek. 2016. The Gradualizer: A Methodology and Algorithm for Generating Gradual Type Systems. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’16). Google Scholar
Digital Library
- Matteo Cimini and Jeremy G. Siek. 2017. Automatically Generating the Dynamic Semantics of Gradually Typed Languages. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017). 789–803. Google Scholar
Digital Library
- Pierre-Èvariste Dagand, Nicolas Tabareau, and Èric Tanter. 2018. Foundations of dependent interoperability. Journal of Functional Programming 28 (2018), e9.Google Scholar
Cross Ref
- Markus Degen, Peter Thiemann, and Stefan Wehr. 2012. The interaction of contracts and laziness. Higher-Order and Symbolic Computation 25 (2012), 85–125. Google Scholar
Digital Library
- Brian Patrick Dunphy. 2002. Parametricity As a Notion of Uniformity in Reflexive Graphs. Ph.D. Dissertation. Champaign, IL, USA. Advisor(s) Reddy, Uday.Google Scholar
- Robert Bruce Findler and Matthias Felleisen. 2002. Contracts for higher-order functions. In International Conference on Functional Programming (ICFP). 48–59. Google Scholar
Digital Library
- Robert Bruce Findler, Matthew Flatt, and Matthias Felleisen. 2004. Semantic Casts: Contracts and Structural Subtyping in a Nominal World. In European Conference on Object-Oriented Programming (ECOOP).Google Scholar
Cross Ref
- Carsten Führmann. 1999. Direct models of the computational lambda-calculus. Electronic Notes in Theoretical Computer Science 20 (1999), 245–292.Google Scholar
Cross Ref
- Ronald Garcia, Alison M. Clark, and Éric Tanter. 2016. Abstracting Gradual Typing. In ACM Symposium on Principles of Programming Languages (POPL). Google Scholar
Digital Library
- Jean-Yves Girard. 2001. Locus Solum: From the rules of logic to the logic of rules. Mathematical Structures in Computer Science 11, 3 (2001), 301âĂŞ506. Google Scholar
Digital Library
- Michael Greenberg. 2015. Space-Efficient Manifest Contracts. In ACM Symposium on Principles of Programming Languages (POPL). 181–194. Google Scholar
Digital Library
- Michael Greenberg, Benjamin C. Pierce, and Stephanie Weirich. 2010. Contracts Made Manifest (POPL ’10). Google Scholar
Digital Library
- Ben Greenman and Matthias Felleisen. 2018. A Spectrum of Type Soundness and Performance. In International Conference on Functional Programming (ICFP), St. Louis, Missouri.Google Scholar
Digital Library
- Fritz Henglein. 1994. Dynamic Typing: Syntax and Proof Theory. 22, 3 (1994), 197–230. Google Scholar
Digital Library
- David Herman, Aaron Tomb, and Cormac Flanagan. 2010. Space-efficient gradual typing. Higher-Order and Symbolic Computation (2010). Google Scholar
Digital Library
- Ralf Hinze, Johan Jeuring, and Andres Löh. 2006. Typed Contracts for Functional Programming. In International Symposium on Functional and Logic Programming (FLOPS). Google Scholar
Digital Library
- Atsushi Igarashi, Peter Thiemann, Vasco T. Vasconcelos, and Philip Wadler. 2017b. Gradual Session Types. Proceedings of ACM Programning Languages 1, ICFP, Article 38 (Aug. 2017), 28 pages. Google Scholar
Digital Library
- Yuu Igarashi, Taro Sekiyama, and Atsushi Igarashi. 2017a. On Polymorphic Gradual Typing. In International Conference on Functional Programming (ICFP), Oxford, United Kingdom.Google Scholar
- Paul Blain Levy. 2003. Call-By-Push-Value: A Functional/Imperative Synthesis. Springer.Google Scholar
- Sam Lindley, Conor McBride, and Craig McLaughlin. 2017. Do Be Do Be Do. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017). ACM, 500–514. Google Scholar
Digital Library
- Jacob Matthews and Amal Ahmed. 2008. Parametric polymorphism through run-time sealing, or, Theorems for low, low prices!. In European Symposium on Programming (ESOP). Google Scholar
Digital Library
- Guillaume Munch-Maccagnoni. 2014. Models of a Non-associative Composition. In Foundations of Software Science and Computation Structures. 396–410.Google Scholar
- Georg Neis, Derek Dreyer, and Andreas Rossberg. 2009. Non-Parametric Parametricity. In International Conference on Functional Programming (ICFP). 135–148. Google Scholar
Digital Library
- Max S. New and Amal Ahmed. 2018. Graduality from Embedding-Projection Pairs. In International Conference on Functional Programming (ICFP), St. Louis, Missouri.Google Scholar
- Max S. New and Daniel R. Licata. 2018. Call-by-name Gradual Type Theory. FSCD (2018).Google Scholar
- Max S. New, Daniel R. Licata, and Amal Ahmed. 2018. Gradual Type Theory (Extend Version). (2018). https://arxiv.org/abs/ 1811.02440 Google Scholar
Digital Library
- Frank Pfenning and Dennis Griffith. 2015. Polarized Substructural Session Types (invited talk). In International Conference on Foundations of Software Science and Computation Structures (FoSSaCS).Google Scholar
Cross Ref
- Gordon D. Plotkin and Martín Abadi. 1993. A Logic for Parametric Polymorphism. In Typed Lambda Calculi and Applications, International Conference on Typed Lambda Calculi and Applications, TLCA ’93, Utrecht, The Netherlands, March 16-18, 1993, Proceedings. 361–375. Google Scholar
Digital Library
- Jeremy Siek, Ronald Garcia, and Walid Taha. 2009. Exploring the Design Space of Higher-Order Casts. In European Symposium on Programming (ESOP). Springer-Verlag, Berlin, Heidelberg, 17–31. Google Scholar
Digital Library
- Jeremy Siek and Sam Tobin-Hochstadt. 2016. The recursive union of some gradual types. A List of Successes That Can Change the World: Essays Dedicated to Philip Wadler on the Occasion of His 60th Birthday (Springer LNCS) volume 9600 (2016).Google Scholar
- Jeremy Siek, Micahel Vitousek, Matteo Cimini, and John Tang Boyland. 2015a. Refined Criteria for Gradual Typing. In 1st Summit on Advances in Programming Languages (SNAPL 2015).Google Scholar
- Jeremy G. Siek and Walid Taha. 2006. Gradual Typing for Functional Languages. In Scheme and Functional Programming Workshop (Scheme). 81–92.Google Scholar
- Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, Sam Tobin-Hochstadt, and Ronald Garcia. 2015b. Monotonic References for Efficient Gradual Typing. In Proceedings of the 24th European Symposium on Programming on Programming Languages and Systems - Volume 9032. Google Scholar
Digital Library
- Jeremy G. Siek and Philip Wadler. 2010. Threesomes, with and Without Blame. In ACM Symposium on Principles of Programming Languages (POPL). ACM, 365–376. Google Scholar
Digital Library
- T. Stephen Strickland, Sam Tobin-Hochstadt, Robert Bruce Findler, and Matthew Flatt. 2012. Chaperones and Impersonators: Run-time Support for Reasonable Interposition (ACM Symposium on Object Oriented Programming: Systems, Languages, and Applications (OOPSLA)). Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. 2006. Interlanguage Migration: From Scripts to Programs. In Dynamic Languages Symposium (DLS). 964–974. Google Scholar
Digital Library
- Michael M. Vitousek, Cameron Swords, and Jeremy G. Siek. 2017. Big Types in Little Runtime: Open-world Soundness and Collaborative Blame for Gradual Type Systems (POPL 2017). Google Scholar
Digital Library
- Philip Wadler and Robert Bruce Findler. 2009. Well-typed programs can’t be blamed. In European Symposium on Programming (ESOP). 1–16. Google Scholar
Digital Library
- Dana N. Xu, Simon Peyton Jones, and Koen Claessen. 2009. Static Contract Checking for Haskell (ACM Symposium on Principles of Programming Languages (POPL), Savannah, Georgia). Google Scholar
Digital Library
- Noam Zeilberger. 2009. The Logical Basis of Evaluation Order and Pattern-Matching. Ph.D. Dissertation. Carnegie Mellon University. Google Scholar
Digital Library
Index Terms
Gradual type theory
Recommendations
Graduality and parametricity: together again for the first time
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 ...
Gradual typing: a new perspective
We define a new, more semantic interpretation of gradual types and use it to ``gradualize'' two forms of polymorphism: subtyping polymorphism and implicit parametric polymorphism. In particular, we use the new interpretation to define three gradual type ...
Dynamic type inference for gradual Hindley–Milner typing
Garcia and Cimini study a type inference problem for the ITGL, an implicitly and gradually typed language with let-polymorphism, and develop a sound and complete inference algorithm for it. Soundness and completeness mean that, if the algorithm succeeds,...






Comments