Abstract
Union types allow to capture the possibility of a term to be of several possibly unrelated types. Traditional static approaches to union types are untagged and tagged unions, which present dual advantages in their use. Inspired by recent work on using abstract interpretation to understand gradual typing, we present a novel design for union types, called gradual union types. Gradual union types combine the advantages of tagged and untagged union types, backed by dynamic checks. Seen as a gradual typing discipline, gradual union types are restricted imprecise types that denote a finite number of static types. We apply the Abstracting Gradual Typing (AGT) methodology of Garcia et al. to derive the static and dynamic semantics of a language that supports both gradual unions and the traditional, totally-unknown type. We uncover that gradual unions interact with the unknown type in a way that mandates a stratified approach to AGT, relying on a composition of two distinct abstract interpretations in order to retain optimality. Thanks to the abstract interpretation framework, the resulting language is type safe and satisfies the refined criteria for gradual languages. We also show how to compile such a language to a threesome cast calculus, and prove that the compilation preserves the semantics and properties of the language.
M. Toro—Funded by CONICYT-PCHA/Doctorado Nacional/2015-21150510.
É. Tanter—Partially funded by FONDECYT Project 1150017.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsNotes
- 1.
Similarly to untagged unions, one could design a language whose conditional expression implicitly introduces imprecision, without the need for any ascription (Sect. 2.2); we do not further consider this possible design and use ascriptions explicitly.
- 2.
We use the hat notation to refer to a set of elements X (e.g. is a set of static types, and is a set of sets of static types).
- 3.
The AI framework provides us with definitions for consistent predicates and functions; we will provide some equivalent algorithmic characterizations.
References
Abadi, M., Cardelli, L., Pierce, B., Plotkin, G.: Dynamic typing in a statically typed language. ACM Trans. Program. Lang. Syst. 13(2), 237–268 (1991)
Ahmed, A., Findler, R.B., Siek, J., Wadler, P.: Blame for all. In: POPL 2011 (2011)
Bañados Schwerter, F., Garcia, R., Tanter, É.: A theory of gradual effect systems. In: ICFP 2014 (2014)
Barbanera, F., Dezani-Ciancaglini, M., De’Liguoro, H.: Intersection and union types: syntax and semantics. Inf. Comput. 119, 202–230 (1995)
Benzaken, V., Castagna, G., Frisch, A.: CDuce: an XML-centric general purpose language. In: ICFP 2003 (2003)
Buneman, P., Pierce, B.: Union types for semistructured data. In: Connor, R., Mendelzon, A. (eds.) DBPL 1999. LNCS, vol. 1949, pp. 184–207. Springer, Heidelberg (2000). doi:10.1007/3-540-44543-9_12
Castagna, G., Lanvin, V.: Gradual typing with union and intersection types. In: ICFP 2017 (2017)
Microsoft Corporation: Typescript language specification. https://www.typescriptlang.org/. Accessed June 2017
Cousot, P., Cousot, R.: Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints. In: POPL 1977 (1977)
Disney, T., Flanagan, C.: Gradual information flow typing. In: STOP 2011 (2011)
Facebook: Flow: a static type checker for JavaScript. https://flow.org/. Accessed June 2017
Frisch, A., Castagna, G., Benzaken, V.: Semantic subtyping. In: LICS 2002 (2002)
Garcia, R., Cimini, M.: Principal type schemes for gradual programs. In: POPL 2015 (2015)
Garcia, R., Clark, A.M., Tanter, É.: Abstracting gradual typing. In: POPL 2016 (2016)
Harper, P.R.: Practical Foundations for Programming Languages. Cambridge University Press, Cambridge (2012)
Henglein, F.: Dynamic typing: syntax and proof theory. Sci. Comput. Program. 22(3), 197–230 (1994)
Herman, D., Tomb, A., Flanagan, C.: Space-efficient gradual typing. In: Trends in Functional Programming (2007)
Hosoya, H., Vouillon, J., Pierce, B.C.: Regular expression types for XML. In: ICFP 2000 (2000)
Jafery, K.A., Dunfield, J.: Sums of uncertainty: refinements go gradual. In: POPL 2017 (2017)
Kent, A.M., Kempe, D., Tobin-Hochstadt, S.: Occurrence typing modulo theories. In: PLDI 2016 (2016)
Lehmann, N., Tanter, É.: Gradual refinement types. In: POPL 2017 (2017)
Pierce, B.C.: Programming with intersection types, union types, and polymorphism. Technical report CMU-CS-91-106 (1991)
Pierce, B.C.: Types and Programming Languages. MIT Press, Cambridge (2002)
Rastogi, A., Chaudhuri, A., Hosmer, B.: The ins and outs of gradual type inference. In: POPL 2012 (2012)
Rompf, T., Amin, N.: Type soundness for dependent object types (DOT). In: OOPSLA 2016 (2016)
Siek, J., Taha, W.: Gradual typing for objects. In: Ernst, E. (ed.) ECOOP 2007. LNCS, vol. 4609, pp. 2–27. Springer, Heidelberg (2007). doi:10.1007/978-3-540-73589-2_2
Siek, J., Tobin-Hochstadt, S.: The recursive union of some gradual types. In: Wadler Festschrift (2016)
Siek, J., Wadler, P.: Threesomes, with and without blame. In: POPL 2010 (2010)
Siek, J.G., Taha, W.: Gradual typing for functional languages. In: Scheme and Functional Programming Workshop (2006)
Siek, J.G., Vitousek, M.M., Cimini, M., Boyland, J.T.: Refined criteria for gradual typing. In: SNAPL 2015 (2015)
Tobin-Hochstadt, S., Felleisen, M.: The design and implementation of typed scheme. In: POPL 2008 (2008)
Tobin-Hochstadt, S., Felleisen, M.: Logical types for untyped languages. In: ICFP 2010 (2010)
Toro, M., Tanter, É.: Gradual union types–complete definition and proofs. Technical report TR/DCC-2017-1, University of Chile, June 2017
Acknowledgments
We thank Gabriel Scherer, Ronald Garcia and the anonymous reviewers for their detailed comments and suggestions.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2017 Springer International Publishing AG
About this paper
Cite this paper
Toro, M., Tanter, É. (2017). A Gradual Interpretation of Union Types. In: Ranzato, F. (eds) Static Analysis. SAS 2017. Lecture Notes in Computer Science(), vol 10422. Springer, Cham. https://doi.org/10.1007/978-3-319-66706-5_19
Download citation
DOI: https://doi.org/10.1007/978-3-319-66706-5_19
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-66705-8
Online ISBN: 978-3-319-66706-5
eBook Packages: Computer ScienceComputer Science (R0)