Skip to main content

A Gradual Interpretation of Union Types

  • Conference paper
  • First Online:

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 10422))

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

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 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. 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. 3.

    The AI framework provides us with definitions for consistent predicates and functions; we will provide some equivalent algorithmic characterizations.

References

  1. 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)

    Article  Google Scholar 

  2. Ahmed, A., Findler, R.B., Siek, J., Wadler, P.: Blame for all. In: POPL 2011 (2011)

    Google Scholar 

  3. Bañados Schwerter, F., Garcia, R., Tanter, É.: A theory of gradual effect systems. In: ICFP 2014 (2014)

    Google Scholar 

  4. Barbanera, F., Dezani-Ciancaglini, M., De’Liguoro, H.: Intersection and union types: syntax and semantics. Inf. Comput. 119, 202–230 (1995)

    Article  MathSciNet  MATH  Google Scholar 

  5. Benzaken, V., Castagna, G., Frisch, A.: CDuce: an XML-centric general purpose language. In: ICFP 2003 (2003)

    Google Scholar 

  6. 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

    Chapter  Google Scholar 

  7. Castagna, G., Lanvin, V.: Gradual typing with union and intersection types. In: ICFP 2017 (2017)

    Google Scholar 

  8. Microsoft Corporation: Typescript language specification. https://www.typescriptlang.org/. Accessed June 2017

  9. 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)

    Google Scholar 

  10. Disney, T., Flanagan, C.: Gradual information flow typing. In: STOP 2011 (2011)

    Google Scholar 

  11. Facebook: Flow: a static type checker for JavaScript. https://flow.org/. Accessed June 2017

  12. Frisch, A., Castagna, G., Benzaken, V.: Semantic subtyping. In: LICS 2002 (2002)

    Google Scholar 

  13. Garcia, R., Cimini, M.: Principal type schemes for gradual programs. In: POPL 2015 (2015)

    Google Scholar 

  14. Garcia, R., Clark, A.M., Tanter, É.: Abstracting gradual typing. In: POPL 2016 (2016)

    Google Scholar 

  15. Harper, P.R.: Practical Foundations for Programming Languages. Cambridge University Press, Cambridge (2012)

    Book  MATH  Google Scholar 

  16. Henglein, F.: Dynamic typing: syntax and proof theory. Sci. Comput. Program. 22(3), 197–230 (1994)

    Article  MathSciNet  MATH  Google Scholar 

  17. Herman, D., Tomb, A., Flanagan, C.: Space-efficient gradual typing. In: Trends in Functional Programming (2007)

    Google Scholar 

  18. Hosoya, H., Vouillon, J., Pierce, B.C.: Regular expression types for XML. In: ICFP 2000 (2000)

    Google Scholar 

  19. Jafery, K.A., Dunfield, J.: Sums of uncertainty: refinements go gradual. In: POPL 2017 (2017)

    Google Scholar 

  20. Kent, A.M., Kempe, D., Tobin-Hochstadt, S.: Occurrence typing modulo theories. In: PLDI 2016 (2016)

    Google Scholar 

  21. Lehmann, N., Tanter, É.: Gradual refinement types. In: POPL 2017 (2017)

    Google Scholar 

  22. Pierce, B.C.: Programming with intersection types, union types, and polymorphism. Technical report CMU-CS-91-106 (1991)

    Google Scholar 

  23. Pierce, B.C.: Types and Programming Languages. MIT Press, Cambridge (2002)

    MATH  Google Scholar 

  24. Rastogi, A., Chaudhuri, A., Hosmer, B.: The ins and outs of gradual type inference. In: POPL 2012 (2012)

    Google Scholar 

  25. Rompf, T., Amin, N.: Type soundness for dependent object types (DOT). In: OOPSLA 2016 (2016)

    Google Scholar 

  26. 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

    Chapter  Google Scholar 

  27. Siek, J., Tobin-Hochstadt, S.: The recursive union of some gradual types. In: Wadler Festschrift (2016)

    Google Scholar 

  28. Siek, J., Wadler, P.: Threesomes, with and without blame. In: POPL 2010 (2010)

    Google Scholar 

  29. Siek, J.G., Taha, W.: Gradual typing for functional languages. In: Scheme and Functional Programming Workshop (2006)

    Google Scholar 

  30. Siek, J.G., Vitousek, M.M., Cimini, M., Boyland, J.T.: Refined criteria for gradual typing. In: SNAPL 2015 (2015)

    Google Scholar 

  31. Tobin-Hochstadt, S., Felleisen, M.: The design and implementation of typed scheme. In: POPL 2008 (2008)

    Google Scholar 

  32. Tobin-Hochstadt, S., Felleisen, M.: Logical types for untyped languages. In: ICFP 2010 (2010)

    Google Scholar 

  33. Toro, M., Tanter, É.: Gradual union types–complete definition and proofs. Technical report TR/DCC-2017-1, University of Chile, June 2017

    Google Scholar 

Download references

Acknowledgments

We thank Gabriel Scherer, Ronald Garcia and the anonymous reviewers for their detailed comments and suggestions.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Matías Toro .

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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)

Publish with us

Policies and ethics