Nothing Special   »   [go: up one dir, main page]

skip to main content
research-article
Open access

A Bowtie for a Beast: Overloading, Eta Expansion, and Extensible Data Types in F⋈

Published: 11 January 2023 Publication History

Abstract

The typed merge operator offers the promise of a compositional style of statically-typed programming in which solutions to the expression problem arise naturally. This approach, dubbed compositional programming, has recently been demonstrated by Zhang et al.
Unfortunately, the merge operator is an unwieldy beast. Merging values from overlapping types may be ambiguous, so disjointness relations have been introduced to rule out undesired nondeterminism and obtain a well-behaved semantics. Past type systems using a disjoint merge operator rely on intersection types, but extending such systems to include union types or overloaded functions is problematic: naively adding either reintroduces ambiguity. In a nutshell: the elimination forms of unions and overloaded functions require values to be distinguishable by case analysis, but the merge operator can create exotic values that violate that requirement.
This paper presents F, a core language that demonstrates how unions, intersections, and overloading can all coexist with a tame merge operator. The key is an underlying design principle that states that any two inhabited types can support either the deterministic merging of their values, or the ability to distinguish their values, but never both. To realize this invariant, we decompose previously studied notions of disjointness into two new, dual relations that permit the operation that best suits each pair of types. This duality respects the polarization of the type structure, yielding an expressive language that we prove to be both type safe and deterministic.

References

[1]
Andreas Abel, Brigitte Pientka, David Thibodeau, and Anton Setzer. 2013. Copatterns: Programming Infinite Structures by Observations. In Proceedings of the 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’13). Association for Computing Machinery, New York, NY, USA. 27–38. isbn:9781450318327
[2]
Jean-Marc Andreoli. 1992. Logic programming with focusing proofs in linear logic. Journal of logic and computation, 2, 3 (1992), 297–347.
[3]
Franco Barbanera, Mariangiola Dezani-Ciancaglini, and Ugo de’Liguoro. 1995. Intersection and Union Types: Syntax and Semantics. Information and Computation, 119, 2 (1995), June, 202–230.
[4]
Henk Barendregt, Mario Coppo, and Mariangiola Dezani-Ciancaglini. 1983. A filter lambda model and the completeness of type assignment. The journal of symbolic logic, 48, 04 (1983), 931–940.
[5]
Xuan Bi and Bruno C. d. S. Oliveira. 2018. Typed First-Class Traits. In European Conference on Object-Oriented Programming (ECOOP).
[6]
Xuan Bi, Bruno C. d. S. Oliveira, and Tom Schrijvers. 2018. The Essence of Nested Composition. In European Conference on Object-Oriented Programming (ECOOP).
[7]
Xuan Bi, Ningning Xie, Bruno C. d. S. Oliveira, and Tom Schrijvers. 2019. Distributive Disjoint Polymorphism for Compositional Programming. In European Symposium on Programming (ESOP).
[8]
Richard Bird and Oege de Moor. 1996. The Algebra of Programming. Prentice-Hall. isbn:013507245X http://www.cs.ox.ac.uk/publications/books/algebra/
[9]
Luca Cardelli and John C. Mitchell. 1990. Operations on Records. In Proceedings of the Fifth International Conference on Mathematical Foundations of Programming Semantics. Springer-Verlag, Berlin, Heidelberg. 22–52. isbn:0387973753
[10]
J. Carette, O. Kiselyov, and C. Shan. 2009. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. Journal of Functional Programming, 19, 05 (2009), 509–543.
[11]
Giuseppe Castagna. 1997. Unifying Overloading and λ -Abstraction: Λ ₍₎. Theor. Comput. Sci., 176, 1–2 (1997), apr, 337–345. issn:0304-3975
[12]
Giuseppe Castagna. 2022. Covariance and Controvariance: a fresh look at an old issue (a primer in advanced type systems for learning functional programmers). Logical Methods in Computer Science, Volume 16, Issue 1 (2022), Feb.
[13]
Giuseppe Castagna, Giorgio Ghelli, and Giuseppe Longo. 1995. A calculus for overloaded functions with subtyping. Information and Computation, 117, 1 (1995), feb, 115–135.
[14]
Giuseppe Castagna, Mickaël Laurent, Kim Nguyễn, and Matthew Lutze. 2022. On Type-Cases, Union Elimination, and Occurrence Typing. Proc. ACM Program. Lang., 6, POPL (2022), Article 13, Jan, 31 pages.
[15]
Adriana B Compagnoni and Benjamin C Pierce. 1996. Higher-order intersection types and multiple inheritance. Mathematical Structures in Computer Science (MSCS), 6, 5 (1996), 469–501.
[16]
William R. Cook, Walter Hill, and Peter S. Canning. 1989. Inheritance is Not Subtyping. In Proceedings of the 17th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’90). Association for Computing Machinery, 125–135.
[17]
Mario Coppo and Mariangiola Dezani-Ciancaglini. 1978. A new type assignment for λ -terms. Archiv. Math. Logik, 19 (1978), Jan, 139–156.
[18]
Patrick Cousot and Radhia Cousot. 1977. Abstract Interpretation: A Unified Lattice Model for Static Analysis of Programs by Construction or Approximation of Fixpoints. In Proceedings of the 4th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages (POPL ’77). Association for Computing Machinery, New York, NY, USA. 238–252. isbn:9781450373500
[19]
Rowan Davies and Frank Pfenning. 2000. Intersection Types and Computational Effects. In Proceedings of the Fifth ACM SIGPLAN International Conference on Functional Programming (ICFP ’00). Association for Computing Machinery, New York, NY, USA. 198–208. isbn:1581132026
[20]
Jana Dunfield. 2012. Annotations for Intersection Typechecking. In Proceedings of the Sixth Workshop on Intersection Types and Related Systems, Stéphane Graham-Lengrand and Luca Paolini (Eds.) (EPTCS, Vol. 121). 35–47.
[21]
Jana Dunfield. 2014. Elaborating Intersection and Union Types. J. Functional Programming, 24, 2–3 (2014), 133–165.
[22]
Jana Dunfield and Frank Pfenning. 2003. Type assignment for intersections and unions in call-by-value languages. In International Conference on Foundations of Software Science and Computation Structures. 250–266.
[23]
Erik Ernst. 2001. Family Polymorphism. In European Conference on Object-Oriented Programming (ECOOP).
[24]
Tim Freeman and Frank Pfenning. 1991. Refinement types for ML. In Proceedings of the ACM SIGPLAN 1991 conference on Programming language design and implementation. 268–277.
[25]
Alain Frisch, Giuseppe Castagna, and Véronique Benzaken. 2008. Semantic Subtyping: Dealing Set-Theoretically with Function, Union, Intersection, and Negation Types. J. ACM, 55, 4 (2008), Article 19, Sep, 64 pages. issn:0004-5411
[26]
Haruo Hosoya and Benjamin C Pierce. 2003. XDuce: A statically typed XML processing language. ACM Transactions on Internet Technology (TOIT), 3, 2 (2003), 117–148.
[27]
Xuejing Huang and Bruno C. d. S. Oliveira. 2021. Distributing intersection and union types with splits and duality (functional pearl). Proceedings of the ACM on Programming Languages, 5, ICFP (2021), 1–24.
[28]
Xuejing Huang, Jinxu Zhao, and Bruno C. D. S. Oliveira. 2021. Taming the Merge Operator. Journal of Functional Programming, 31 (2021), issn:0956-7968, 1469-7653
[29]
Atsushi Igarashi and Hideshi Nagira. 2006. Union types for object-oriented programming. In Proceedings of the 2006 ACM symposium on Applied computing. 1435–1441.
[30]
Gavin King. 2013. The Ceylon language specification, version 1.0. https://ceylon-lang.org/documentation/1.0/spec/
[31]
David MacQueen, Gordon Plotkin, and Ravi Sethi. 1984. An ideal model for recursive polymorphic types. In Proceedings of the 11th ACM SIGACT-SIGPLAN symposium on Principles of programming languages. 165–174.
[32]
Robin Milner. 1978. A Theory of Type Polymorphism in Programming. J. Comput. System Sci., 17 (1978), Aug., 348–375.
[33]
Martin Odersky, Philippe Altherr, Vincent Cremet, Burak Emir, Sebastian Maneth, Stéphane Micheloud, Nikolay Mihaylov, Michel Schinz, Erik Stenman, and Matthias Zenger. 2004. An overview of the Scala programming language. EPFL.
[34]
Bruno C. d. S. Oliveira and William R. Cook. 2012. Extensibility for the Masses. In European Conference on Object-Oriented Programming (ECOOP).
[35]
Bruno C. d. S. Oliveira, Zhiyuan Shi, and João Alpuim. 2016. Disjoint intersection types. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016). Association for Computing Machinery, 364–377. isbn:978-1-4503-4219-3
[36]
Dominic Orchard and Tom Schrijvers. 2010. Haskell Type Constraints Unleashed. In Proceedings of the 10th International Conference on Functional and Logic Programming (FLOPS’10). Springer-Verlag, Berlin, Heidelberg. 56–71. isbn:3642122507
[37]
Benjamin C Pierce. 1991. Programming with intersection types and bounded polymorphism. Ph.D. Dissertation. CMU-CS-91-205, Carnegie Mellon University.
[38]
Benjamin C Pierce. 1991. Programming with intersection types, union types, and polymorphism.
[39]
Garrel Pottinger. 1980. A type assignment for the strongly normalizable λ -terms. To HB Curry: essays on combinatory logic, lambda calculus and formalism, 561–577. Academic Press.
[40]
Baber Rehman, Xuejing Huang, Ningning Xie, and Bruno C. d. S. Oliveira. 2022. Union Types with Disjoint Switches. In 36th European Conference on Object-Oriented Programming, ECOOP 2022, June 6-10, 2022, Berlin, Germany, Karim Ali and Jan Vitek (Eds.) (LIPIcs, Vol. 222).
[41]
John C. Reynolds. 1988. Preliminary design of the programming language Forsythe. CMU-CS-88-159, Carnegie Mellon University.
[42]
John C. Reynolds. 1997. Design of the Programming Language FORSYTHE. Birkhauser Boston Inc., USA. 173–233. isbn:0817638806
[43]
Nick Rioux, Xuejing Huang, Bruno C. d. S. Oliveira, and Steve Zdancewic. 2022. A Bowtie for a Beast (Artifact). https://doi.org/10.5281/zenodo.7409103
[44]
Nick Rioux, Xuejing Huang, Bruno C. d. S. Oliveira, and Steve Zdancewic. 2022. A Bowtie for a Beast (Technical Appendix). MS-CIS-22-02, University of Pennsylvania.
[45]
Tiark Rompf and Nada Amin. 2016. Type Soundness for Dependent Object Types (DOT). In Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA 2016). Association for Computing Machinery, 624–641.
[46]
Jeremy G. Siek and Walid Taha. 2006. Gradual typing for functional languages. In Proceedings of the Scheme and Functional Programming Workshop (Scheme). ACM, 81–92.
[47]
Steffen van Bakel, Mariangiola Dezani-Ciancaglini, Ugo de’Liguoro, and Yoko Motohama. 2000. The minimal relevant logic and the call-by-value lambda calculus. TR-ARP-05-2000, The Australian National University.
[48]
Philip Wadler. 1998. The expression problem. Java-genericity mailing list, https://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt
[49]
Mitchell Wand. 1989. Type Inference for Record Concatenation and Multiple Inheritance. In Symposium on Logic in Computer Science (LICS).
[50]
A.K. Wright and M. Felleisen. 1994. A Syntactic Approach to Type Soundness. Inf. Comput., 115, 1 (1994), Nov, 38–94. issn:0890-5401
[51]
Zhiwu Xu. 2013. Parametric Polymorphism for XML Processing Languages. Ph.D. Dissertation. Université Paris-Diderot-Paris VII.
[52]
Noam Zeilberger. 2008. Focusing and Higher-Order Abstract Syntax. In Proceedings of the 35th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’08). Association for Computing Machinery, New York, NY, USA. 359–369. isbn:9781595936899
[53]
Weixin Zhang, Yaozhu Sun, and Bruno C. d. S. Oliveira. 2021. Compositional Programming. ACM Transactions on Programming Languages and Systems, April.

Cited By

View all
  • (2024)Disjoint Polymorphism with Intersection and Union TypesProceedings of the 26th ACM International Workshop on Formal Techniques for Java-like Programs10.1145/3678721.3686230(23-29)Online publication date: 20-Sep-2024
  • (2024)Contextual TypingProceedings of the ACM on Programming Languages10.1145/36746558:ICFP(880-908)Online publication date: 15-Aug-2024
  • (2024)Polymorphic Type Inference for Dynamic LanguagesProceedings of the ACM on Programming Languages10.1145/36328828:POPL(1179-1210)Online publication date: 5-Jan-2024

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 7, Issue POPL
January 2023
2196 pages
EISSN:2475-1421
DOI:10.1145/3554308
  • Editor:
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution 4.0 International License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 11 January 2023
Published in PACMPL Volume 7, Issue POPL

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. extensibility
  2. polymorphism
  3. type systems

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)343
  • Downloads (Last 6 weeks)45
Reflects downloads up to 14 Nov 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Disjoint Polymorphism with Intersection and Union TypesProceedings of the 26th ACM International Workshop on Formal Techniques for Java-like Programs10.1145/3678721.3686230(23-29)Online publication date: 20-Sep-2024
  • (2024)Contextual TypingProceedings of the ACM on Programming Languages10.1145/36746558:ICFP(880-908)Online publication date: 15-Aug-2024
  • (2024)Polymorphic Type Inference for Dynamic LanguagesProceedings of the ACM on Programming Languages10.1145/36328828:POPL(1179-1210)Online publication date: 5-Jan-2024
  • (2023)Generic Programming with Extensible Data Types: Or, Making Ad Hoc Extensible Data Types Less Ad HocProceedings of the ACM on Programming Languages10.1145/36078437:ICFP(356-384)Online publication date: 31-Aug-2023

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media