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.
- 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 Google ScholarDigital Library
- Jean-Marc Andreoli. 1992. Logic programming with focusing proofs in linear logic. Journal of logic and computation, 2, 3 (1992), 297–347. Google ScholarCross Ref
- 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. Google ScholarDigital Library
- 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. Google Scholar
- Xuan Bi and Bruno C. d. S. Oliveira. 2018. Typed First-Class Traits. In European Conference on Object-Oriented Programming (ECOOP). Google Scholar
- Xuan Bi, Bruno C. d. S. Oliveira, and Tom Schrijvers. 2018. The Essence of Nested Composition. In European Conference on Object-Oriented Programming (ECOOP). Google Scholar
- 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). Google Scholar
- Richard Bird and Oege de Moor. 1996. The Algebra of Programming. Prentice-Hall. isbn:013507245X http://www.cs.ox.ac.uk/publications/books/algebra/ Google ScholarDigital Library
- 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 Google Scholar
- 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. Google ScholarDigital Library
- Giuseppe Castagna. 1997. Unifying Overloading and λ -Abstraction: Λ ₍₎. Theor. Comput. Sci., 176, 1–2 (1997), apr, 337–345. issn:0304-3975 Google ScholarDigital Library
- 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.. Google Scholar
- Giuseppe Castagna, Giorgio Ghelli, and Giuseppe Longo. 1995. A calculus for overloaded functions with subtyping. Information and Computation, 117, 1 (1995), feb, 115–135. Google Scholar
- 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. Google ScholarDigital Library
- 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. Google ScholarCross Ref
- 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. Google Scholar
- Mario Coppo and Mariangiola Dezani-Ciancaglini. 1978. A new type assignment for λ -terms. Archiv. Math. Logik, 19 (1978), Jan, 139–156. Google Scholar
- 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 Google ScholarDigital Library
- 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 Google ScholarDigital Library
- 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. Google Scholar
- Jana Dunfield. 2014. Elaborating Intersection and Union Types. J. Functional Programming, 24, 2–3 (2014), 133–165. Google ScholarCross Ref
- 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. Google ScholarCross Ref
- Erik Ernst. 2001. Family Polymorphism. In European Conference on Object-Oriented Programming (ECOOP). Google Scholar
- 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. Google ScholarDigital Library
- 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 Google ScholarDigital Library
- 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. Google ScholarDigital Library
- 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. Google Scholar
- 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 Google Scholar
- Atsushi Igarashi and Hideshi Nagira. 2006. Union types for object-oriented programming. In Proceedings of the 2006 ACM symposium on Applied computing. 1435–1441. Google ScholarDigital Library
- Gavin King. 2013. The Ceylon language specification, version 1.0. https://ceylon-lang.org/documentation/1.0/spec/ Google Scholar
- 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. Google ScholarDigital Library
- Robin Milner. 1978. A Theory of Type Polymorphism in Programming. J. Comput. System Sci., 17 (1978), Aug., 348–375. Google ScholarCross Ref
- 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. Google Scholar
- Bruno C. d. S. Oliveira and William R. Cook. 2012. Extensibility for the Masses. In European Conference on Object-Oriented Programming (ECOOP). Google Scholar
- 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 Google ScholarDigital Library
- 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 Google ScholarDigital Library
- Benjamin C Pierce. 1991. Programming with intersection types and bounded polymorphism. Ph.D. Dissertation. CMU-CS-91-205, Carnegie Mellon University. Google ScholarDigital Library
- Benjamin C Pierce. 1991. Programming with intersection types, union types, and polymorphism. Google Scholar
- 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. Google Scholar
- 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). Google Scholar
- John C. Reynolds. 1988. Preliminary design of the programming language Forsythe. CMU-CS-88-159, Carnegie Mellon University. Google Scholar
- John C. Reynolds. 1997. Design of the Programming Language FORSYTHE. Birkhauser Boston Inc., USA. 173–233. isbn:0817638806 Google Scholar
- 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 Google ScholarDigital Library
- 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. Google Scholar
- 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. Google ScholarDigital Library
- 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. Google Scholar
- 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. Google Scholar
- Philip Wadler. 1998. The expression problem. Java-genericity mailing list, https://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt Google Scholar
- Mitchell Wand. 1989. Type Inference for Record Concatenation and Multiple Inheritance. In Symposium on Logic in Computer Science (LICS). Google Scholar
- A.K. Wright and M. Felleisen. 1994. A Syntactic Approach to Type Soundness. Inf. Comput., 115, 1 (1994), Nov, 38–94. issn:0890-5401 Google Scholar
- Zhiwu Xu. 2013. Parametric Polymorphism for XML Processing Languages. Ph.D. Dissertation. Université Paris-Diderot-Paris VII. Google Scholar
- 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 Google ScholarDigital Library
- Weixin Zhang, Yaozhu Sun, and Bruno C. d. S. Oliveira. 2021. Compositional Programming. ACM Transactions on Programming Languages and Systems, April. Google Scholar
Index Terms
- A Bowtie for a Beast: Overloading, Eta Expansion, and Extensible Data Types in F⋈
Recommendations
Type inference, principal typings, and let-polymorphism for first-class mixin modules
Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingA mixin module is a programming abstraction that simultaneously generalizes λ-abstractions, records, and mutually recursive definitions. Although various mixin module type systems have been developed, no one has investigated principal typings or ...
Type inference, principal typings, and let-polymorphism for first-class mixin modules
ICFP '05: Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingA mixin module is a programming abstraction that simultaneously generalizes λ-abstractions, records, and mutually recursive definitions. Although various mixin module type systems have been developed, no one has investigated principal typings or ...
System F with coercion constraints
CSL-LICS '14: Proceedings of the Joint Meeting of the Twenty-Third EACSL Annual Conference on Computer Science Logic (CSL) and the Twenty-Ninth Annual ACM/IEEE Symposium on Logic in Computer Science (LICS)We present a second-order λ-calculus with coercion constraints that generalizes a previous extension of System F with parametric coercion abstractions by allowing multiple but simultaneous type and coercion abstractions, as well as recursive coercions ...
Comments