Abstract
Dynamically-typed languages offer easy interaction with ad hoc data such as JSON and S-expressions; statically-typed languages offer powerful tools for working with structured data, notably algebraic datatypes, which are a core feature of typed languages both functional and otherwise. Gradual typing aims to reconcile dynamic and static typing smoothly. The gradual typing literature has extensively focused on the computational aspect of types, such as type safety, effects, noninterference, or parametricity, but the application of graduality to data structuring mechanisms has been much less explored. While row polymorphism and set-theoretic types have been studied in the context of gradual typing, algebraic datatypes in particular have not, which is surprising considering their wide use in practice. We develop, formalize, and prototype a novel approach to gradually structured data with algebraic datatypes. Gradually structured data bridges the gap between traditional algebraic datatypes and flexible data management mechanisms such as tagged data in dynamic languages, or polymorphic variants in OCaml. We illustrate the key ideas of gradual algebraic datatypes through the evolution of a small server application from dynamic to progressively more static checking, formalize a core functional language with gradually structured data, and establish its metatheory, including the gradual guarantees.
Supplemental Material
- Amal Ahmed, Robert Bruce Findler, Jeremy G. Siek, and Philip Wadler. 2011. Blame for All. In Proceedings of the 38th annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2011). ACM Press, Austin, Texas, USA. 201–214. https://doi.org/10.1145/1926385.1926409 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. Proceedings of the ACM on Programming Languages, 1, ICFP (2017), Sept., 39:1–39:28. https://doi.org/10.1145/3110283 Google Scholar
Digital Library
- Felipe Bañados Schwerter, Alison M Clark, Khurram A Jafery, and Ronald Garcia. 2021. Abstracting gradual typing moving forward: precise and space-efficient. Proceedings of the ACM on Programming Languages, 5, POPL (2021), Jan., 1–28. https://doi.org/10.1145/3434342 Google Scholar
Digital Library
- Felipe Bañados Schwerter, Ronald Garcia, and Éric Tanter. 2014. A Theory of Gradual Effect Systems. In Proceedings of the 19th ACM SIGPLAN Conference on Functional Programming (ICFP 2014). ACM Press, Gothenburg, Sweden. 283–295. https://doi.org/10.1145/2692915.2628149 Google Scholar
Digital Library
- Felipe Bañados Schwerter, Ronald Garcia, and Éric Tanter. 2016. Gradual Type-and-Effect Systems. Journal of Functional Programming, 26 (2016), Sept., 19:1–19:69. https://doi.org/10.1017/S0956796816000162 Google Scholar
Cross Ref
- Spenser Bauman, Carl Friedrich Bolz-Tereick, Jeremy Siek, and Sam Tobin-Hochstadt. 2017. Sound gradual typing: Only mostly dead. Proceedings of the ACM on Programming Languages, 1, OOPSLA (2017), Oct., 1–24. https://doi.org/10.1145/3133878 Google Scholar
Digital Library
- Véronique Benzaken, Giuseppe Castagna, and Alain Frisch. 2003. CDuce: An XML-Centric General Purpose Language. In Proceedings of the 8th ACM SIGPLAN Conference on Functional Programming (ICFP 2003). ACM Press, Uppsala, Sweden. https://doi.org/10.1145/944705.944711 Google Scholar
Digital Library
- Peter Buneman. 1997. Semistructured Data. In Proceedings of the Sixteenth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems (Principles of Database Systems). ACM Press, New York, NY, USA. 117–121. https://doi.org/10.1145/263661.263675 Google Scholar
Digital Library
- John Peter Campora, Sheng Chen, and Eric Walkingshaw. 2018. Casts and costs: Harmonizing safety and performance in gradual typing. Proceedings of the ACM on Programming Languages, 2, ICFP (2018), Sept., 1–30. https://doi.org/10.1145/3236793 Google Scholar
Digital Library
- Giuseppe Castagna and Victor Lanvin. 2017. Gradual Typing with Union and Intersection Types. Proceedings of the ACM on Programming Languages, 1, ICFP (2017), Sept., 41:1–41:28. https://doi.org/10.1145/3110285 Google Scholar
Digital Library
- Giuseppe Castagna, Victor Lanvin, Tommaso Petrucciani, and Jeremy G. Siek. 2019. Gradual typing: a new perspective. Proceedings of the ACM on Programming Languages, 3, POPL (2019), Jan., 16:1–16:32. https://doi.org/10.1145/3290329 Google Scholar
Digital Library
- Evan Czaplicki and Stephen Chong. 2013. Asynchronous Functional Reactive Programming for GUIs. In Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2013). ACM Press, Seattle, Washington, USA. 411–422. https://doi.org/10.1145/2499370.2462161 Google Scholar
Digital Library
- Mike Fagan. 1991. Soft typing: An approach to type checking for dynamically typed languages. Ph.D. Dissertation. Rice University. https://scholarship.rice.edu/handle/1911/16439Google Scholar
- Matthias Felleisen and Daniel P. Friedman. 1986. Control Operators, the SECD-Machine, and the λ -calculus. In Proceedings of IFIP Working Conference on Formal Descriptions of Programming Concepts, Martin Wirsing (Ed.). Ebberup, Denmark. 193–219.Google Scholar
- Ronald Garcia and Matteo Cimini. 2015. Principal Type Schemes for Gradual Programs. In Proceedings of the 42nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2015). ACM Press, Mumbai, India. 303–315. https://doi.org/10.1145/2775051.2676992 Google Scholar
Digital Library
- Ronald Garcia, Alison M. Clark, and Éric Tanter. 2016. Abstracting Gradual Typing. In Proceedings of the 43rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2016), Rastislav Bodík and Rupak Majumdar (Eds.). ACM Press, St Petersburg, FL, USA. 429–442. https://doi.org/10.1145/2837614.2837670 See erratum: https://www.cs.ubc.ca/ rxg/agt-erratum.pdf. Google Scholar
Digital Library
- Ronald Garcia, Éric Tanter, Roger Wolff, and Jonathan Aldrich. 2014. Foundations of Typestate-Oriented Programming. ACM Transactions on Programming Languages and Systems, 36, 4 (2014), Article 12, Oct., 12:1–12:44 pages. https://doi.org/10.1145/2629609 Google Scholar
Digital Library
- Jacques Garrigue. 1998. Programming with polymorphic variants. In ML Workshop. 13, 7.Google Scholar
- Panicz Maciej Godek. 2020. SRFI 200: Pattern Matching. https://srfi.schemers.org/srfi-200/srfi-200.htmlGoogle Scholar
- Michael Greenberg. 2019. The Dynamic Practice and Static Theory of Gradual Typing. In 3rd Summit on Advances in Programming Languages (SNAPL 2019), Benjamin S. Lerner, Rastislav Bodík, and Shriram Krishnamurthi (Eds.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 136). Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Providence, RI, USA. 6:1–6:20. https://doi.org/10.4230/LIPIcs.SNAPL.2019.6 Google Scholar
Cross Ref
- Ben Greenman, Asumu Takikawa, Max S New, Daniel Feltey, Robert Bruce Findler, Jan Vitek, and Matthias Felleisen. 2019. How to evaluate the performance of gradual type systems. jfp, 29 (2019), https://doi.org/10.1017/S0956796818000217 Google Scholar
Cross Ref
- David Herman, Aaron Tomb, and Cormac Flanagan. 2010. Space-efficient gradual typing. Higher-Order and Sympolic Computation, 23, 2 (2010), June, 167–189. https://doi.org/10.1007/s10990-011-9066-z Google Scholar
Digital Library
- Atsushi Igarashi, Peter Thiemann, Vasco T. Vasconcelos, and Philip Wadler. 2017. Gradual Session Types. Proceedings of the ACM on Programming Languages, 1, ICFP (2017), Sept., 38:1–38:28. https://doi.org/10.1145/3110282 Google Scholar
Digital Library
- Yuu Igarashi, Taro Sekiyama, and Atsushi Igarashi. 2017. On Polymorphic Gradual Typing. Proceedings of the ACM on Programming Languages, 1, ICFP (2017), Sept., 40:1–40:29. https://doi.org/10.1145/3110284 Google Scholar
Digital Library
- Khurram A. Jafery and Joshua Dunfield. 2017. Sums of Uncertainty: Refinements Go Gradual. In Proceedings of the 44th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2017). ACM Press, Paris, France. 804–817. https://doi.org/10.1145/3009837.3009865 Google Scholar
Digital Library
- Richard Kelsey. 1999. SRFI 9: Defining Record Types. https://srfi.schemers.org/srfi-9/srfi-9.htmlGoogle Scholar
- Steve Klabnik and Carol Nichols. 2018. The Rust Programming Language. No Starch Press.Google Scholar
- Andre Kuhlenschmidt, Deyaaeldeen Almahallawi, and Jeremy G Siek. 2019. Toward efficient gradual typing for structural types via coercions. In Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2019). ACM Press, Phoenix, AZ, USA. 517–532. https://doi.org/10.1145/3314221.3314627 Google Scholar
Digital Library
- Nico Lehmann and Éric Tanter. 2017. Gradual Refinement Types. In Proceedings of the 44th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2017). ACM Press, Paris, France. 775–788. https://doi.org/10.1145/3009837.3009856 Google Scholar
Digital Library
- Daan Leijen. 2017. Type Directed Compilation of Row-Typed Algebraic Effects. In Proceedings of the 44th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2017). ACM Press, Paris, France. 486–499. https://doi.org/10.1145/3093333.3009872 Google Scholar
Digital Library
- Xavier Leroy, Damien Doligez, Alain Frisch, Jacques Garrigue, Didier Rémy, and Jérôme Vouillon. 2021. The OCaml system, release 4.12, Documentation and user’s manual.. 27 Jan., https://ocaml.org/releases/4.12/ocaml-4.12-refman.pdfGoogle Scholar
- Max S. New, Dustin Jamner, and Amal Ahmed. 2020. Graduality and Parametricity: Together Again for the First Time. Proceedings of the ACM on Programming Languages, 4, POPL (2020), Jan., 46:1–46:32. https://doi.org/10.1145/3371114 Google Scholar
Digital Library
- Martin Odersky, Philippe Altherr, Vincent Cremet, Burak Emir, Sebastian Maneth, Stéphane Micheloud, Nikolay Mihaylov, Michel Schinz, Erik Stenman, and Matthias Zenger. 2006. An overview of the Scala programming language. EPFL. https://www.scala-lang.org/docu/files/ScalaOverview.pdfGoogle Scholar
- Oxford. 2021. Oxford Advanced Learner’s Dictionary (10th ed.). Oxford University Press. Evidence.Google Scholar
- Taro Sekiyama and Atsushi Igarashi. 2020. Gradual Typing for Extensibility by Rows. Jan., Workshop on Gradual Typing (WGT).Google Scholar
- Ilya Sergey and Dave Clarke. 2012. Gradual Ownership Types. In Proceedings of the 21st European Symposium on Programming Languages and Systems (ESOP 2012), Helmut Seidl (Ed.) (Lecture Notes in Computer Science, Vol. 7211). Springer-Verlag, Tallinn, Estonia. 579–599. https://doi.org/10.1007/978-3-642-28869-2_29 Google Scholar
Digital Library
- Jeremy Siek and Walid Taha. 2006. Gradual Typing for Functional Languages. In Proceedings of the Scheme and Functional Programming Workshop. 81–92.Google Scholar
- Jeremy Siek and Walid Taha. 2007. Gradual Typing for Objects. In Proceedings of the 21st European Conference on Object-oriented Programming (ECOOP 2007), Erik Ernst (Ed.) (Lecture Notes in Computer Science, 4609). Springer-Verlag, Berlin, Germany. 2–27. https://doi.org/10.1007/978-3-540-73589-2_2 Google Scholar
Digital Library
- Jeremy Siek and Sam Tobin-Hochstadt. 2016. The Recursive Union of Some Gradual Types. In Wadler Festschrift (Lecture Notes in Computer Science, Vol. 9600). Springer-Verlag, 388–410. https://doi.org/10.1007/978-3-319-30936-1_21 Google Scholar
Cross Ref
- Jeremy Siek and Philip Wadler. 2010. Threesomes, with and without blame. In Proceedings of the 37th annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2010). ACM Press, Madrid, Spain. 365–376. https://doi.org/10.1145/1707801.1706342 Google Scholar
Digital Library
- Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, and John Tang Boyland. 2015. Refined Criteria for Gradual Typing. In 1st Summit on Advances in Programming Languages (SNAPL 2015) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 32). Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Asilomar, California, USA. 274–293. https://doi.org/10.4230/LIPIcs.SNAPL.2015.274 Google Scholar
Cross Ref
- Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, Sam Tobin-Hochstadt, and Ronald Garcia. 2015. Monotonic References for Efficient Gradual Typing. In Proceedings of the 24th European Symposium on Programming Languages and Systems (ESOP 2015), Jan Vitek (Ed.) (Lecture Notes in Computer Science, Vol. 9032). Springer-Verlag, London, UK. 432–456. https://doi.org/10.1007/978-3-662-46669-8_18 Google Scholar
Digital Library
- Martin Sulzmann, Manuel MT Chakravarty, Simon Peyton Jones, and Kevin Donnelly. 2007. System F with type equality coercions. In Proceedings of the 2007 ACM SIGPLAN international workshop on Types in languages design and implementation. acm, Nice, France. 53–66. https://doi.org/10.1145/1190315.1190324 Google Scholar
Digital Library
- Asumu Takikawa, Daniel Feltey, Ben Greenman, Max S. New, Jan Vitek, and Matthias Felleisen. 2016. Is sound gradual typing dead? In Proceedings of the 43rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2016), Rastislav Bodík and Rupak Majumdar (Eds.). ACM Press, St Petersburg, FL, USA. 456–468. https://doi.org/10.1145/2837614.2837630 Google Scholar
Digital Library
- Asumu Takikawa, T. Stephen Strickland, Christos Dimoulas, Sam Tobin-Hochstadt, and Matthias Felleisen. 2012. Gradual Typing for First-Class Classes. In Proceedings of the 27th ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA 2012). ACM Press, Tucson, AZ, USA. 793–810. https://doi.org/10.1145/2398857.2384674 Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. 2008. The Design and Implementation of Typed Scheme. In Proceedings of the 35th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2008). ACM Press, San Francisco, CA, USA. 395–406. https://doi.org/10.1145/1328438.1328486 Google Scholar
Digital Library
- Sam Tobin-Hochstadt, Vincent St-Amour, and Eric Dobson. 2014. The Typed Racket Reference.Google Scholar
- Matías Toro, Elizabeth Labrada, and Éric Tanter. 2019. Gradual Parametricity, Revisited. Proceedings of the ACM on Programming Languages, 3, POPL (2019), Jan., 17:1–17:30. https://doi.org/10.1145/3290330 Google Scholar
Digital Library
- Matías Toro and Éric Tanter. 2017. A Gradual Interpretation of Union Types. In Proceedings of the 24th Static Analysis Symposium (SAS 2017) (Lecture Notes in Computer Science, Vol. 10422). Springer-Verlag, New York City, NY, USA. 382–404. https://doi.org/10.1007/978-3-319-66706-5_19 Google Scholar
Cross Ref
- Matías Toro and Éric Tanter. 2020. Abstracting Gradual References. Science of Computer Programming, 197 (2020), Oct., 1–65. https://doi.org/10.1016/j.scico.2020.102496 Google Scholar
Cross Ref
- Niki Vazou, Éric Tanter, and David Van Horn. 2018. Gradual Liquid Type Inference. Proceedings of the ACM on Programming Languages, 2, OOPSLA (2018), Nov., 132:1–132:25. https://doi.org/10.1145/3276502 Google Scholar
Digital Library
- Mitchell Wand. 1987. Complete Type Inference for Simple Objects. In Proceedings of the Symposium on Logic in Computer Science (LICS 1987). IEEE Computer Society Press, Ithaca, New York, USA. 37–44.Google Scholar
- Mitchell Wand. 1991. Type inference for record concatenation and multiple inheritance. Information and Computation, 93, 1 (1991), 1–15. https://doi.org/10.1016/0890-5401(91)90050-C Selections from 1989 IEEE Symposium on Logic in Computer Science. Google Scholar
Digital Library
- Roger Wolff, Ronald Garcia, Éric Tanter, and Jonathan Aldrich. 2011. Gradual Typestate. In Proceedings of the 25th European Conference on Object-oriented Programming (ECOOP 2011), Mira Mezini (Ed.) (Lecture Notes in Computer Science, Vol. 6813). Springer-Verlag, Lancaster, UK. 459–483. https://doi.org/10.1007/978-3-642-22655-7_22 Google Scholar
Cross Ref
- Matthias Zenger and Martin Odersky. 2001. Extensible Algebraic Datatypes with Defaults. In Proceedings of the 6th ACM SIGPLAN Conference on Functional Programming (ICFP 2001). ACM Press, Florence, Italy. 241–252. https://doi.org/10.1145/507635.507665 Google Scholar
Digital Library
Index Terms
Gradually structured data
Recommendations
Interpretations of the gradually-typed lambda calculus
Scheme '12: Proceedings of the 2012 Annual Workshop on Scheme and Functional ProgrammingGradual typing is an approach to integrating static and dynamic type checking within the same language [Siek and Taha 2006]. Given the name "gradual typing", one might think that the most interesting aspect is the type system. It turns out that the ...
Cast insertion strategies for gradually-typed objects
DLS '13: Proceedings of the 9th symposium on Dynamic languagesGradual typing enables a smooth and progressive integration of static and dynamic typing. The semantics of a gradually-typed program is given by translation to an intermediate language with casts: runtime type checks that control the boundaries between ...
Cast insertion strategies for gradually-typed objects
DLS '13Gradual typing enables a smooth and progressive integration of static and dynamic typing. The semantics of a gradually-typed program is given by translation to an intermediate language with casts: runtime type checks that control the boundaries between ...






Comments