Abstract
Developing and maintaining software commonly requires (1) adding new data type constructors to existing applications, but also (2) adding new functions that work on existing data. Most programming languages have native support for defining data types and functions in a way that supports either (1) or (2), but not both. This lack of native support makes it difficult to use and extend libraries. A theoretically well-studied solution is to define data types and functions using initial algebra semantics. While it is possible to encode this solution in existing programming languages, such encodings add syntactic and interpretive overhead, and commonly fail to take advantage of the map and fold fusion laws of initial algebras which compilers could exploit to generate more efficient code. A solution to these is to provide native support for initial algebra semantics. In this paper, we develop such a solution and present a type discipline and core calculus for a language with native support for initial algebra semantics.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
This intuition is made formal in the extended version [33, Theorem 1].
- 2.
For presentational purposes, we omit some necessary restrictions on sizes here. The extended version [33, §4] defines these restrictions and the precise semantics.
- 3.
- 4.
Here, we mean “\(\beta \)-reduction” in the more general sense of simplifying an application of an elimination form to an introduction form.
- 5.
This property implies what Devesas Campos and Levy [15] call soundness of the denotational model with respect to the operational model. Their soundness property is about a big-step relation; ours is small-step.
References
Abbott, M.G., Altenkirch, T., Ghani, N.: Containers: constructing strictly positive types. Theor. Comput. Sci. 342(1), 3–27 (2005). https://doi.org/10.1016/j.tcs.2005.06.002
Abel, A., Matthes, R.: (Co-)Iteration for higher-order nested datatypes. In: Geuvers, H., Wiedijk, F. (eds.) TYPES 2002. LNCS, vol. 2646, pp. 1–20. Springer, Heidelberg (2003). https://doi.org/10.1007/3-540-39185-1_1
Abel, A., Matthes, R., Uustalu, T.: Generalized iteration and coiteration for higher-order nested datatypes. In: Gordon, A.D. (ed.) FoSSaCS 2003. LNCS, vol. 2620, pp. 54–69. Springer, Heidelberg (2003). https://doi.org/10.1007/3-540-36576-1_4
Abel, A., Matthes, R., Uustalu, T.: Iteration and coiteration schemes for higher-order and nested datatypes. Theor. Comput. Sci. 333(1–2), 3–66 (2005)
Adámek, J.: Free algebras and automata realizations in the language of categories. Comment. Math. Univ. Carol. 15(4), 589–602 (1974)
Benke, M., Dybjer, P., Jansson, P.: Universes for generic programs and proofs in dependent type theory. Nord. J. Comput. 10(4), 265–289 (2003)
van den Berg, B., Schrijvers, T., Poulsen, C.B., Wu, N.: Latent effects for reusable language components. In: Oh, H. (ed.) APLAS 2021. LNCS, vol. 13008, pp. 182–201. Springer, Cham (2021). https://doi.org/10.1007/978-3-030-89051-3_11
Bird, R., Meertens, L.: Nested datatypes. In: Jeuring, J. (ed.) MPC 1998. LNCS, vol. 1422, pp. 52–67. Springer, Heidelberg (1998). https://doi.org/10.1007/BFb0054285
Bird, R.S., Paterson, R.: Generalised folds for nested datatypes. Formal Aspects Comput. 11(2), 200–222 (1999). https://doi.org/10.1007/s001650050047
Cai, Y., Giarrusso, P.G., Ostermann, K.: System f-omega with equirecursive types for datatype-generic programming. In: Bodík, R., Majumdar, R. (eds.) Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, St. Petersburg, FL, USA, 20–22 January 2016, pp. 30–43. ACM (2016). https://doi.org/10.1145/2837614.2837660
Carette, J., Kiselyov, O., Shan, C.: Finally tagless, partially evaluated: tagless staged interpreters for simpler typed languages. J. Funct. Program. 19(5), 509–543 (2009). https://doi.org/10.1017/S0956796809007205
Chapman, J., Dagand, P., McBride, C., Morris, P.: The gentle art of levitation. In: Hudak, P., Weirich, S. (eds.) Proceeding of the 15th ACM SIGPLAN international conference on Functional programming, ICFP 2010, Baltimore, Maryland, USA, 27–29 September 2010, pp. 3–14. ACM (2010), https://doi.org/10.1145/1863543.1863547
Coquand, T., Paulin, C.: Inductively defined types. In: Martin-Löf, P., Mints, G. (eds.) COLOG 1988. LNCS, vol. 417, pp. 50–66. Springer, Heidelberg (1990). https://doi.org/10.1007/3-540-52335-9_47
Dagand, P.: A cosmology of datatypes: reusability and dependent types. Ph.D. thesis, University of Strathclyde, Glasgow, UK (2013). https://oleg.lib.strath.ac.uk/R/?func=dbin-jump-full &object_id=22713
Devesas Campos, M., Levy, P.B.: A syntactic view of computational adequacy. In: Baier, C., Dal Lago, U. (eds.) FoSSaCS 2018. LNCS, vol. 10803, pp. 71–87. Springer, Cham (2018). https://doi.org/10.1007/978-3-319-89366-2_4
Felleisen, M., Hieb, R.: The revised report on the syntactic theories of sequential control and state. Theor. Comput. Sci. 103(2), 235–271 (1992). https://doi.org/10.1016/0304-3975(92)90014-7
Glimming, J., Ghani, N.: Difunctorial semantics of object calculus. In: Bono, V., Bugliesi, M., Drossopoulou, S. (eds.) Proceedings of the Second Workshop on Object Oriented Developments, WOOD 2004, London, UK, 30 August 2004. ENTCS, vol. 138, pp. 79–94. Elsevier (2004). https://doi.org/10.1016/j.entcs.2005.09.012
Goguen, J.A.: An intial algebra approach to the specification, correctness and implementation of abstract data types. IBM Research Report 6487 (1976)
Hubers, A., Morris, J.G.: Generic programming with extensible data types: Or, making ad hoc extensible data types less ad hoc. Proc. ACM Program. Lang. 7(ICFP) (2023). https://doi.org/10.1145/3607843
Johann, P., Ghiorzi, E.: Parametricity for nested types and gadts. Log. Methods Comput. Sci. 17(4) (2021). https://doi.org/10.46298/lmcs-17(4:23)2021
Johann, P., Ghiorzi, E., Jeffries, D.: Parametricity for primitive nested types. In: FOSSACS 2021. LNCS, vol. 12650, pp. 324–343. Springer, Cham (2021). https://doi.org/10.1007/978-3-030-71995-1_17
Johann, P., Polonsky, A.: Higher-kinded data types: syntax and semantics. In: 34th Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2019, Vancouver, BC, Canada, 24–27 June 2019, pp. 1–13. IEEE (2019), https://doi.org/10.1109/LICS.2019.8785657
Kammar, O., Lindley, S., Oury, N.: Handlers in action. In: Morrisett, G., Uustalu, T. (eds.) ACM SIGPLAN International Conference on Functional Programming, ICFP 2013, Boston, MA, USA, 25–27 September 2013, pp. 145–158. ACM (2013). https://doi.org/10.1145/2500365.2500590
Kieburtz, R.B., Lewis, J.: Programming with algebras. In: Jeuring, J., Meijer, E. (eds.) AFP 1995. LNCS, vol. 925, pp. 267–307. Springer, Heidelberg (1995). https://doi.org/10.1007/3-540-59451-5_8
Kiselyov, O.: Typed tagless final interpreters. In: Gibbons, J. (ed.) Generic and Indexed Programming. LNCS, vol. 7470, pp. 130–174. Springer, Heidelberg (2012). https://doi.org/10.1007/978-3-642-32202-0_3
Mac Lane, S.: Categories for the Working Mathematician. GTM, vol. 5. Springer, New York (1978). https://doi.org/10.1007/978-1-4757-4721-8
Meijer, E., Fokkinga, M., Paterson, R.: Functional programming with bananas, lenses, envelopes and barbed wire. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 124–144. Springer, Heidelberg (1991). https://doi.org/10.1007/3540543961_7
Moggi, E.: Notions of computation and monads. Inf. Comput. 93(1), 55–92 (1991). https://doi.org/10.1016/0890-5401(91)90052-4
Morris, J.G., McKinna, J.: Abstracting extensible data types: or, rows by any other name. Proc. ACM Program. Lang. 3(POPL), 12:1–12:28 (2019). https://doi.org/10.1145/3290325
Plotkin, G., Pretnar, M.: Handlers of algebraic effects. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 80–94. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-00590-9_7
Poulsen, C.B., van der Rest, C.: Hefty algebras: modular elaboration of higher-order algebraic effects. Proc. ACM Program. Lang. 7(POPL), 1801–1831 (2023). https://doi.org/10.1145/3571255
van der Rest, C., Poulsen, C.B.: Towards a language for defining reusable programming language components - (project paper). In: Swierstra, W., Wu, N. (eds.) Trends in Functional Programming - 23rd International Symposium, TFP 2022, Virtual Event, March 17–18, 2022, Revised Selected Papers. LNCS, vol. 13401, pp. 18–38. Springer, Cham (2022). https://doi.org/10.1007/978-3-031-21314-4_2
van der Rest, C., Poulsen, C.B.: Types and semantics for extensible data types (extended version) (2023)
Reynolds, J.C.: Definitional interpreters for higher-order programming languages. High. Order Symb. Comput. 11(4), 363–397 (1998). https://doi.org/10.1023/A:1010027404223
Schrijvers, T., Piróg, M., Wu, N., Jaskelioff, M.: Monad transformers and modular algebraic effects: what binds them together. In: Eisenberg, R.A. (ed.) Proceedings of the 12th ACM SIGPLAN International Symposium on Haskell, Haskell@ICFP 2019, Berlin, Germany, 18–23 August 2019, pp. 98–113. ACM (2019). https://doi.org/10.1145/3331545.3342595
Swierstra, W.: Data types à la carte. J. Funct. Program. 18(4), 423–436 (2008). https://doi.org/10.1017/S0956796808006758
Uustalu, T., Vene, V.: Mendler-style inductive types, categorically. Nord. J. Comput. 6(3), 343 (1999)
Wadler, P.: The expression problem. https://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt (1998), Accessed 1 Jul 2020
Wand, M.: Final algebra semantics and data type extensions. J. Comput. Syst. Sci. 19(1), 27–44 (1979). https://doi.org/10.1016/0022-0000(79)90011-4
Wu, N., Schrijvers, T., Hinze, R.: Effect handlers in scope. In: Swierstra, W. (ed.) Proceedings of the 2014 ACM SIGPLAN symposium on Haskell, Gothenburg, Sweden, 4–5 September 2014, pp. 1–12. ACM (2014), https://doi.org/10.1145/2633357.2633358
Yang, Z., Paviotti, M., Wu, N., van den Berg, B., Schrijvers, T.: Structured handling of scoped effects. In: ESOP 2022. LNCS, vol. 13240, pp. 462–491. Springer, Cham (2022). https://doi.org/10.1007/978-3-030-99336-8_17
Zhang, W., Sun, Y., d. S. Oliveira, B.C.: Compositional programming. ACM Trans. Program. Lang. Syst. 43(3), 9:1–9:61 (2021). https://doi.org/10.1145/3460228
Acknowledgements
This research was partially funded by the NWO VENI Composable and Safe-by-Construction Programming Language Definitions project (VI.Veni.192.259).
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2023 The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd.
About this paper
Cite this paper
van der Rest, C., Poulsen, C.B. (2023). Types and Semantics for Extensible Data Types. In: Hur, CK. (eds) Programming Languages and Systems. APLAS 2023. Lecture Notes in Computer Science, vol 14405. Springer, Singapore. https://doi.org/10.1007/978-981-99-8311-7_3
Download citation
DOI: https://doi.org/10.1007/978-981-99-8311-7_3
Published:
Publisher Name: Springer, Singapore
Print ISBN: 978-981-99-8310-0
Online ISBN: 978-981-99-8311-7
eBook Packages: Computer ScienceComputer Science (R0)