skip to main content

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

Published:11 January 2023Publication History
Skip Abstract Section

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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Jean-Marc Andreoli. 1992. Logic programming with focusing proofs in linear logic. Journal of logic and computation, 2, 3 (1992), 297–347. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle Scholar
  5. Xuan Bi and Bruno C. d. S. Oliveira. 2018. Typed First-Class Traits. In European Conference on Object-Oriented Programming (ECOOP). Google ScholarGoogle Scholar
  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). Google ScholarGoogle Scholar
  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). Google ScholarGoogle Scholar
  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/ Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Giuseppe Castagna. 1997. Unifying Overloading and λ -Abstraction: Λ ₍₎. Theor. Comput. Sci., 176, 1–2 (1997), apr, 337–345. issn:0304-3975 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.. Google ScholarGoogle Scholar
  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. Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle Scholar
  17. Mario Coppo and Mariangiola Dezani-Ciancaglini. 1978. A new type assignment for λ -terms. Archiv. Math. Logik, 19 (1978), Jan, 139–156. Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle Scholar
  21. Jana Dunfield. 2014. Elaborating Intersection and Union Types. J. Functional Programming, 24, 2–3 (2014), 133–165. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle ScholarCross RefCross Ref
  23. Erik Ernst. 2001. Family Polymorphism. In European Conference on Object-Oriented Programming (ECOOP). Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle Scholar
  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 Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Gavin King. 2013. The Ceylon language specification, version 1.0. https://ceylon-lang.org/documentation/1.0/spec/ Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Robin Milner. 1978. A Theory of Type Polymorphism in Programming. J. Comput. System Sci., 17 (1978), Aug., 348–375. Google ScholarGoogle ScholarCross RefCross Ref
  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. Google ScholarGoogle Scholar
  34. Bruno C. d. S. Oliveira and William R. Cook. 2012. Extensibility for the Masses. In European Conference on Object-Oriented Programming (ECOOP). Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Benjamin C Pierce. 1991. Programming with intersection types and bounded polymorphism. Ph.D. Dissertation. CMU-CS-91-205, Carnegie Mellon University. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Benjamin C Pierce. 1991. Programming with intersection types, union types, and polymorphism. Google ScholarGoogle Scholar
  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. Google ScholarGoogle Scholar
  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). Google ScholarGoogle Scholar
  41. John C. Reynolds. 1988. Preliminary design of the programming language Forsythe. CMU-CS-88-159, Carnegie Mellon University. Google ScholarGoogle Scholar
  42. John C. Reynolds. 1997. Design of the Programming Language FORSYTHE. Birkhauser Boston Inc., USA. 173–233. isbn:0817638806 Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle Scholar
  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. Google ScholarGoogle ScholarDigital LibraryDigital Library
  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. Google ScholarGoogle Scholar
  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. Google ScholarGoogle Scholar
  48. Philip Wadler. 1998. The expression problem. Java-genericity mailing list, https://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt Google ScholarGoogle Scholar
  49. Mitchell Wand. 1989. Type Inference for Record Concatenation and Multiple Inheritance. In Symposium on Logic in Computer Science (LICS). Google ScholarGoogle Scholar
  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 Google ScholarGoogle Scholar
  51. Zhiwu Xu. 2013. Parametric Polymorphism for XML Processing Languages. Ph.D. Dissertation. Université Paris-Diderot-Paris VII. Google ScholarGoogle Scholar
  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 Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Weixin Zhang, Yaozhu Sun, and Bruno C. d. S. Oliveira. 2021. Compositional Programming. ACM Transactions on Programming Languages and Systems, April. Google ScholarGoogle Scholar

Index Terms

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

          Recommendations

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in

          Full Access

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader