Hostname: page-component-848d4c4894-x5gtn Total loading time: 0 Render date: 2024-06-12T15:09:00.191Z Has data issue: false hasContentIssue false

Gradual type theory

Published online by Cambridge University Press:  14 October 2021

MAX S. NEW
Affiliation:
Khoury College of Computer Sciences, Northeastern University, Boston, MA 02115, USA (e-mail: maxsnew@umich.edu)
DANIEL R. LICATA
Affiliation:
Mathematics and Computer Science, Wesleyan University, Middletown, CT 06459, USA (e-mail: dlicata@wesleyan.edu)
AMAL AHMED
Affiliation:
Khoury College of Computer Sciences, Northeastern University, Boston, MA 02115, USA (e-mail: amal@ccs.neu.edu)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

Gradually 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 call gradual 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 called graduality, 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 graduality must violate 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.

Type
Research Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution, and reproduction in any medium, provided the original work is properly cited.
Copyright
© The Author(s), 2021. Published by Cambridge University Press

References

Ahman, D., Ghani, N. & Plotkin, G. D. (2016) Dependent types and fibred computational effects. In Foundations of Software Science and Computation Structures, pp. 36–54.CrossRefGoogle Scholar
Ahmed, A. (2006) Step-indexed syntactic logical relations for recursive and quantified types. In European Symposium on Programming (ESOP), pp. 69–83.CrossRefGoogle Scholar
Bauer, A. & Pretnar, M. (2013) An effect system for algebraic effects and handlers. In Algebra and Coalgebra in Computer Science, pp. 116. Berlin, Heidelberg: Springer.Google Scholar
Boyland, J. (2014) The problem of structural type tests in a gradually typed language. In 21st Workshop on Foundations of Object-Oriented Languages.Google Scholar
Cimini, M. & Siek, J. G. (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.CrossRefGoogle Scholar
Cimini, M. & Siek, J. G. (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, pp. 789–803.CrossRefGoogle Scholar
Dagand, P.-È., Tabareau, N. & Tanter, È. (2018) Foundations of dependent interoperability. J. Funct. Program. 28, e9.CrossRefGoogle Scholar
Degen, M., Thiemann, P. & Wehr, S. (2012) The interaction of contracts and laziness. Higher-Order Symb. Comput. 25, 85125.CrossRefGoogle Scholar
Eremondi, J., Tanter, È. & Garcia, R. (2019) Approximate normalization for dependent gradual types. In International Conference on Functional Programming (ICFP), Berlin, Germany.CrossRefGoogle Scholar
Findler, R. B. & Felleisen, M. (2002) Contracts for higher-order functions. In International Conference on Functional Programming (ICFP), pp. 48–59.CrossRefGoogle Scholar
Findler, R. B., Flatt, M. & Felleisen, M. (2004) Semantic casts: Contracts and structural subtyping in a nominal world. In European Conference on Object-Oriented Programming (ECOOP).CrossRefGoogle Scholar
Führmann, C. (1999) Direct models of the computational lambda-calculus. Electr. Notes Theor. Comput. Sci. 20, 245292.CrossRefGoogle Scholar
Garcia, R., Clark, A. M. & Tanter, É. (2016) Abstracting gradual typing. In ACM Symposium on Principles of Programming Languages (POPL).CrossRefGoogle Scholar
Girard, J.-Y. (2001) Locus solum: From the rules of logic to the logic of rules. Math. Struct. Comput. Sci. 11(3), 301506.CrossRefGoogle Scholar
Greenberg, M. (2015) Space-efficient manifest contracts. In ACM Symposium on Principles of Programming Languages (POPL), pp. 181–194.CrossRefGoogle Scholar
Greenberg, M., Pierce, B. C. & Weirich, S. (2010) Contracts made manifest. In ACM Symposium on Principles of Programming Languages (POPL), Madrid, Spain.CrossRefGoogle Scholar
Greenman, B. & Felleisen, M. (2018) A spectrum of type soundness and performance. In International Conference on Functional Programming (ICFP), St. Louis, Missouri.CrossRefGoogle Scholar
Henglein, F. (1994) Dynamic typing: Syntax and proof theory. Sci. Comput. Program. 22(3), 197230.CrossRefGoogle Scholar
Herman, D., Tomb, A. & Flanagan, C. (2010) Space-efficient gradual typing. Higher-Order Symb. Comput. 23, 167.CrossRefGoogle Scholar
Hinze, R., Jeuring, J. & Löh, A. (2006) Typed contracts for functional programming. In International Symposium on Functional and Logic Programming (FLOPS).CrossRefGoogle Scholar
Igarashi, A., Thiemann, P., Vasconcelos, V. T. & Wadler, P. (2017) Gradual session types. Proc. ACM Program. Lang. 1(ICFP), 38:138:28.CrossRefGoogle Scholar
Levy, P. B. (2003) Call-by-Push-Value: A Functional/Imperative Synthesis. Springer.CrossRefGoogle Scholar
Levy, P. B. (2017) Contextual isomorphisms. In ACM Symposium on Principles of Programming Languages (POPL).CrossRefGoogle Scholar
Lindenhovius, B., Mislove, M. & Zamdzhiev, V. (2019) Mixed linear and non-linear recursive types. Proc. ACM Program. Lang. 3(ICFP) 11, 1–29.Please provide page range for “Lindenhovius et al. (2019).”CrossRefGoogle Scholar
Lindley, S., McBride, C. & McLaughlin, C. (2017) Do be do be do. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages. POPL 2017. ACM, pp. 500–514.CrossRefGoogle Scholar
Moggi, E. (1991) Notions of computation and monads. Inf. Comput. 93(1), 55–92.Please provide page range for “Moggi (1991).”CrossRefGoogle Scholar
Munch-Maccagnoni, G. (2014) Models of a non-associative composition. In Foundations of Software Science and Computation Structures, pp. 396–410.CrossRefGoogle Scholar
Nakano, H. (2000) A modality for recursion. In IEEE Symposium on Logic in Computer Science (LICS), Santa Barbara, California.Google Scholar
New, M. S. & Ahmed, A. (2018) Graduality from embedding-projection pairs. In International Conference on Functional Programming (ICFP), St. Louis, Missouri.CrossRefGoogle Scholar
New, M. S. & Licata, D. R. (2018) Call-by-name gradual type theory. In FSCD.Google Scholar
New, M. S. & Licata, D. R. (2020) Call-by-name gradual type theory. In LMCS.Google Scholar
New, M. S., Licata, D. R. & Ahmed, A. (2019) Gradual type theory. In ACM Symposium on Principles of Programming Languages (POPL), Cascais, Portugal.CrossRefGoogle Scholar
New, M. S., Jamner, D. & Ahmed, A. (2020) Graduality and parametricity: Together again for the first time. In ACM Symposium on Principles of Programming Languages (POPL), New Orleans, Louisiana.CrossRefGoogle Scholar
Pédrot, P.-M. & Tabareau, N. (2020) The fire triangle: How to mix substitution, dependent elimination, and effects. In ACM Symposium on Principles of Programming Languages (POPL), New Orleans, Louisiana.CrossRefGoogle Scholar
Pfenning, F. & Griffith, D. (2015) Polarized substructural session types (invited talk). In International Conference on Foundations of Software Science and Computation Structures (FoSSaCS).CrossRefGoogle Scholar
Pitts, A. & Stark, I. (1998) Operational reasoning for functions with local state. In Higher Order Operational Techniques in Semantics, Gordon, A. & Pitts, A. (eds), Publications of the Newton Institute, Cambridge University Press, pp. 227–273.Google Scholar
Siek, J., Garcia, R. & Taha, W. (2009) Exploring the design space of higher-order casts. In European Symposium on Programming (ESOP). Berlin, Heidelberg: Springer-Verlag, pp. 17–31.CrossRefGoogle Scholar
Siek, J. & Tobin-Hochstadt, S. (2016) The recursive union of some gradual types. In A List of Successes that can Change the World: Essays Dedicated to Philip Wadler on the Occasion of His 60th Birthday, LNCS, Springer, vol. 9600.CrossRefGoogle Scholar
Siek, J., Vitousek, M., Cimini, M. & Boyland, J. T. (2015) Refined criteria for gradual typing. In 1st Summit on Advances in Programming Languages. SNAPL 2015.Google Scholar
Siek, J. G. & Taha, W. (2006) Gradual typing for functional languages. In Scheme and Functional Programming Workshop (Scheme), pp. 81–92.Google Scholar
Siek, J. G. & Wadler, P. (2010) Threesomes, with and without blame. In ACM Symposium on Principles of Programming Languages (POPL). ACM, pp. 365–376.CrossRefGoogle Scholar
Strickland, T. S., Tobin-Hochstadt, S., Findler, R. B. & Flatt, M. (2012) Chaperones and impersonators: Run-time support for reasonable interposition. In ACM Symposium on Object Oriented Programming: Systems, Languages, and Applications (OOPSLA), Tucson, Arizona.CrossRefGoogle Scholar
Takikawa, A., Feltey, D., Greenman, B., New, M. S., Vitek, J. & Felleisen, M. (2016) Is sound gradual typing dead? In ACM Symposium on Principles of Programming Languages (POPL), St. Petersburg, Florida.Google Scholar
Tobin-Hochstadt, S. & Felleisen, M. (2006) Interlanguage migration: From scripts to programs. In Dynamic Languages Symposium (DLS), pp. 964–974.CrossRefGoogle Scholar
Tobin-Hochstadt, S. & Felleisen, M. (2008) The design and implementation of typed scheme. In ACM Symposium on Principles of Programming Languages (POPL), San Francisco, California.CrossRefGoogle Scholar
Vitousek, M. M., Swords, C. & Siek, J. G. (2017) Big types in little runtime: Open-world soundness and collaborative blame for gradual type systems. In ACM Symposium on Principles of Programming Languages (POPL), Paris, France.CrossRefGoogle Scholar
Wadler, P. & Findler, R. B. (2009) Well-typed programs can’t be blamed. In European Symposium on Programming (ESOP), pp. 1–16.CrossRefGoogle Scholar
Xu, D. N., Peyton Jones, S. & Claessen, K. (2009) Static contract checking for haskell. In ACM Symposium on Principles of Programming Languages (POPL), Savannah, Georgia.CrossRefGoogle Scholar
Zeilberger, N. (2009) The Logical Basis of Evaluation Order and Pattern-Matching. Ph.D. thesis, Carnegie Mellon University.Google Scholar
Submit a response

Discussions

No Discussions have been published for this article.