skip to main content
research-article
Open access

Persimmon: Nested Family Polymorphism with Extensible Variant Types

Published: 29 April 2024 Publication History

Abstract

Many obstacles stand in the way of modular, extensible code. Some language constructs, such as pattern matching, are not easily extensible. Inherited code may not be type safe in the presence of extended types. The burden of setting up design patterns can discourage users, and parameter clutter can make the code less readable. Given these challenges, it is no wonder that extensibility often gives way to code duplication. We present our solution: Persimmon, a functional system with nested family polymorphism, extensible variant types, and extensible pattern matching. Most constructs in our language are built-in "extensibility hooks," cutting down on the parameter clutter and user burden associated with extensible code. Persimmon preserves the relationships between nested families upon inheritance, enabling extensibility at a large scale. Since nested family polymorphism can express composable extensions, Persimmon supports mixins via an encoding. We show how Persimmon can be compiled into a functional language without extensible variants with our translation to Scala. Finally, we show that our system is sound by proving the properties of progress and preservation.

Supplementary Material

Auxiliary Archive (oopslaa24main-p80-p-archive.zip)
We include our appendix and proofs as supplemental material.

References

[1]
Florent Balestrieri and Michel Mauny. 2018. Generic programming in OCaml. arXiv preprint arXiv:1812.11665.
[2]
Matthias Blume, Umut A. Acar, and Wonseok Chae. 2006. Extensible programming with first-class cases. In Proceedings of the eleventh ACM SIGPLAN international conference on Functional programming - ICFP ’06. ACM Press, New York, New York, USA. 239. isbn:1595933093 https://doi.org/10.1145/1159803.1159836
[3]
Luca Cardelli. 1997. Program fragments, linking, and modularization. In Proceedings of the 24th ACM SIGPLAN-SIGACT symposium on Principles of programming languages. 266–277.
[4]
Jacques Carette, Oleg Kiselyov, and Chung-chieh Shan. 2009. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. Journal of Functional Programming, 19, 5 (2009), 509–543.
[5]
Manuel M. T. Chakravarty, Gabriele Keller, Simon Peyton Jones, and Simon Marlow. 2005. Associated Types with Class. In ACM Symp. on Principles of Programming Languages (POPL).
[6]
Dave Clarke, Sophia Drossopoulou, James Noble, and Tobias Wrigstad. 2007. Tribe: a simple virtual class calculus. In Proceedings of the 6th international conference on Aspect-oriented software development. 121–134.
[7]
Burak Emir, Martin Odersky, and John Williams. 2007. Matching objects with patterns. In European Conference on Object-Oriented Programming. 273–298.
[8]
Erik Ernst. 2001. Family Polymorphism. In ECOOP 2001 — Object-Oriented Programming, Jørgen Lindskov Knudsen, Gerhard Goos, Juris Hartmanis, and Jan van Leeuwen (Eds.) (Lecture notes in computer science, Vol. 2072). Springer Berlin Heidelberg, Berlin, Heidelberg. 303–326. isbn:978-3-540-42206-8 issn:0302-9743 https://doi.org/10.1007/3-540-45337-7_17
[9]
Erik Ernst. 2003. Higher-order hierarchies. In European Conference on Object-Oriented Programming. 303–328.
[10]
Erik Ernst, Klaus Ostermann, and William R Cook. 2006. A virtual class calculus. In Conference record of the 33rd ACM SIGPLAN-SIGACT symposium on Principles of programming languages. 270–282.
[11]
Andong Fan and Lionel Parreaux. 2023. super-Charging Object-Oriented Programming Through Precise Typing of Open Recursion. In 37th European Conference on Object-Oriented Programming (ECOOP 2023).
[12]
Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. 1994. Design Patterns: Elements of Reusable Object-Oriented Software. Addison Wesley.
[13]
Jacques Garrigue. 1998. Programming with polymorphic variants. In ML workshop. 13.
[14]
Jacques Garrigue. 2000. Code reuse through polymorphic variants. Sasaguri, Japan.
[15]
Benedict R Gaster and Mark P Jones. 1996. A polymorphic type system for extensible records and variants. Technical Report NOTTCS-TR-96-3, Department of Computer Science, University of Nottingham.
[16]
Atsushi Igarashi, Chieri Saito, and Mirko Viroli. 2005. Lightweight Family Polymorphism. In Programming languages and systems, Kwangkeun Yi, David Hutchison, Takeo Kanade, Josef Kittler, Jon M. Kleinberg, Friedemann Mattern, John C. Mitchell, Moni Naor, Oscar Nierstrasz, C. Pandu Rangan, Bernhard Steffen, Madhu Sudan, Demetri Terzopoulos, Dough Tygar, Moshe Y. Vardi, and Gerhard Weikum (Eds.) (Lecture notes in computer science, Vol. 3780). Springer Berlin Heidelberg, Berlin, Heidelberg. 161–177. isbn:978-3-540-29735-2 issn:0302-9743 https://doi.org/10.1007/11575467_12
[17]
Atsushi Igarashi and Mirko Viroli. 2007. Variant path types for scalable extensibility. In Proceedings of the 22nd annual ACM SIGPLAN conference on Object-oriented programming systems, languages and applications. 113–132.
[18]
Chinawat Isradisaikul and Andrew C. Myers. 2013. Reconciling Exhaustive Pattern Matching with Objects. In Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’13). Association for Computing Machinery, New York, NY, USA. 343–354. isbn:9781450320146 https://doi.org/10.1145/2491956.2462194
[19]
Ende Jin, Nada Amin, and Yizhou Zhang. 2023. Extensible Metatheory Mechanization via Family Polymorphism. Proceedings of the ACM on Programming Languages, 7, PLDI (2023), https://doi.org/10.1145/3591286
[20]
Oleg Kiselyov. 2012. Typed tagless final interpreters. In Generic and Indexed Programming. Springer, 130–174.
[21]
Anastasiya Kravchuk-Kirilyuk, Gary Feng, Jonas Iskander, Yizhou Zhang, and Nada Amin. 2024. Persimmon: Nested Family Polymorphism with Extensible Variant Types (Artifact). https://doi.org/10.5281/zenodo.10798266
[22]
Andres Löh and Ralf Hinze. 2006. Open data types and open functions. In Proceedings of the 8th ACM SIGPLAN symposium on Principles and practice of declarative programming - PPDP ’06. ACM Press, New York, New York, USA. 133. isbn:1595933883 https://doi.org/10.1145/1140335.1140352
[23]
O. Lehrmann Madsen, B. Møller-Pedersen, and K. Nygaard. 1993. Object Oriented Programming in the BETA Programming Language. Addison-Wesley.
[24]
Todd Millstein, Colin Bleckner, and Craig Chambers. 2004. Modular typechecking for hierarchically extensible datatypes and functions. ACM Transactions on Programming Languages and Systems (TOPLAS), 26, 5 (2004), 836–889.
[25]
Nathaniel Nystrom, Stephen Chong, and Andrew C. Myers. 2004. Scalable extensibility via nested inheritance. In Proceedings of the 19th annual ACM SIGPLAN Conference on Object-oriented programming, systems, languages, and applications - OOPSLA ’04. ACM Press, New York, New York, USA. 99. isbn:1581138319 https://doi.org/10.1145/1028976.1028986
[26]
Nathaniel Nystrom, Xin Qi, and Andrew C Myers. 2006. J& nested intersection for scalable software composition. ACM SIGPLAN Notices, 41, 10 (2006), 21–36.
[27]
Martin Odersky and Matthias Zenger. 2005. Independently Extensible Solutions to the Expression Problem. ACM.
[28]
Martin Odersky and Matthias Zenger. 2005. Scalable component abstractions. In Proceedings of the 20th annual ACM SIGPLAN conference on Object oriented programming systems languages and applications - OOPSLA ’05. ACM Press, New York, New York, USA. 41. isbn:1595930310 https://doi.org/10.1145/1094811.1094815
[29]
Bruno C. d. S. Oliveira and William R. Cook. 2012. Extensibility for the masses. In ECOOP 2012 – Object-Oriented Programming, James Noble, David Hutchison, Takeo Kanade, Josef Kittler, Jon M. Kleinberg, Friedemann Mattern, John C. Mitchell, Moni Naor, Oscar Nierstrasz, C. Pandu Rangan, Bernhard Steffen, Madhu Sudan, Demetri Terzopoulos, Doug Tygar, Moshe Y. Vardi, and Gerhard Weikum (Eds.) (Lecture notes in computer science, Vol. 7313). Springer Berlin Heidelberg, Berlin, Heidelberg. 2–27. isbn:978-3-642-31056-0 issn:0302-9743 https://doi.org/10.1007/978-3-642-31057-7_2
[30]
Simon Peyton Jones. 2009. Classes, Jim, But Not as We Know Them—Type Classes in Haskell: What, Why, and Whither. In European Conf. on Object-Oriented Programming.
[31]
Don Syme, Gregory Neverov, and James Margetson. 2007. Extensible pattern matching via a lightweight language extension. In Proceedings of the 12th ACM SIGPLAN international conference on Functional programming. 29–40.
[32]
Kresten Krab Thorup. 1997. Genericity in Java with virtual types. In European Conf. on Object-Oriented Programming.
[33]
Sam Tobin-Hochstadt. 2011. Extensible pattern matching in an extensible language. arXiv preprint arXiv:1106.2578.
[34]
Philip Wadler. 1998. The expression problem. Discussion on Java-Genericity mailing list. https://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt
[35]
Matthias Zenger and Martin Odersky. 2001. Extensible algebraic datatypes with defaults. In Proceedings of the sixth ACM SIGPLAN international conference on Functional programming. 241–252.
[36]
Weixin Zhang and Bruno C. d. S. Oliveira. 2020. Castor: Programming with extensible generative visitors. Science of Computer Programming, 193 (2020), 102449.
[37]
Weixin Zhang, Yaozhu Sun, and Bruno C. D. S. Oliveira. 2021. Compositional Programming. ACM Transactions on Programming Languages and Systems, 43, 3 (2021), 30 sep, 1–61. issn:0164-0925 https://doi.org/10.1145/3460228
[38]
Yizhou Zhang and Andrew C. Myers. 2017. Familia: unifying interfaces, type classes, and family polymorphism. Proceedings of the ACM on Programming Languages, 1, OOPSLA (2017), 12 oct, 1–31. issn:24751421 https://doi.org/10.1145/3133894

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 8, Issue OOPSLA1
April 2024
1492 pages
EISSN:2475-1421
DOI:10.1145/3554316
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution International 4.0 License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 29 April 2024
Published in PACMPL Volume 8, Issue OOPSLA1

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. Persimmon
  2. composable extensions
  3. extensibility
  4. family polymorphism
  5. nested inheritance

Qualifiers

  • Research-article

Funding Sources

  • NSF (National Science Foundation)
  • Amazon Research Awards

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 427
    Total Downloads
  • Downloads (Last 12 months)427
  • Downloads (Last 6 weeks)49
Reflects downloads up to 25 Dec 2024

Other Metrics

Citations

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media