skip to main content

Making a Type Difference: Subtraction on Intersection Types as Generalized Record Operations

Published:11 January 2023Publication History
Skip Abstract Section

Abstract

In programming languages with records, objects, or traits, it is common to have operators that allow dropping, updating or renaming some components. These operators are useful for programmers to explicitly deal with conflicts and override or update some components. While such operators have been studied for record types, little work has been done to generalize and study their theory for other types.

This paper shows that, given subtyping and disjointness relations, we can specify and derive algorithmic implementations for a general type difference operator that works for other types, including function types, record types and intersection types. When defined in this way, the type difference algebra has many desired properties that are expected from a subtraction operator. Together with a generic merge operator, using type difference we can generalize many operations on records formalized in the literature. To illustrate the usefulness of type difference we create an intermediate calculus with a rich set of operators on expressions of arbitrary type, and demonstrate applications of these operators in CP, a prototype language for Compositional Programming. The semantics of the calculus is given by elaborating into a calculus with disjoint intersection types and a merge operator. We have implemented type difference and all the operators in the CP language. Moreover, all the calculi and related proofs are mechanically formalized in the Coq theorem prover.

References

  1. João Alpuim, Bruno C. d. S. Oliveira, and Zhiyuan Shi. 2017. Disjoint Polymorphism. In European Symposium on Programming (ESOP). https://doi.org/10.1145/1391289.1391293 Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Sandra Alves and Miguel Ramos. 2021. An ML-style Record Calculus with Extensible Records. Electronic Proceedings in Theoretical Computer Science, 351 (2021), dec, 1–17. https://doi.org/10.4204/eptcs.351.1 Google ScholarGoogle ScholarCross RefCross Ref
  3. Davide Ancona, Giovanni Lagorio, and Elena Zucca. 2003. Jam—designing a Java extension with mixins. ACM Transactions on Programming Languages and Systems (TOPLAS), 25, 5 (2003), 641–712. https://doi.org/10.1145/937563.937567 Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Davide Ancona and Elena Zucca. 1998. A theory of mixin modules: Basic and derived operators. Mathematical structures in computer science, 8, 4 (1998), 401–446. https://doi.org/10.1017/S0960129598002576 Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Davide Ancona and Elena Zucca. 2002. A calculus of module systems. Journal of functional programming, 12, 2 (2002), 91–132. https://doi.org/10.1017/S0956796801004257 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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
  7. 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, 4 (1983), 931–940. issn:00224812 http://www.jstor.org/stable/2273659 Google ScholarGoogle ScholarCross RefCross Ref
  8. Véronique Benzaken, Giuseppe Castagna, Kim Nguyen, and Jérôme Siméon. 2013. Static and dynamic semantics of NoSQL languages. ACM SIGPLAN Notices, 48, 1 (2013), 101–114. https://doi.org/10.1145/2480359.2429083 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Xuan Bi and Bruno C. d. S. Oliveira. 2018. Typed First-Class Traits. In 32nd European Conference on Object-Oriented Programming (ECOOP 2018). https://doi.org/10.4230/LIPIcs.ECOOP.2018.9 Google ScholarGoogle ScholarCross RefCross Ref
  10. Xuan Bi, Bruno C. d. S. Oliveira, and Tom Schrijvers. 2018. The Essence of Nested Composition. In 32nd European Conference on Object-Oriented Programming, ECOOP 2018, July 16-21, 2018, Amsterdam, The Netherlands, Todd D. Millstein (Ed.) (LIPIcs, Vol. 109). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 22:1–22:33. https://doi.org/10.4230/LIPIcs.ECOOP.2018.22 Google ScholarGoogle ScholarCross RefCross Ref
  11. 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). https://doi.org/10.1007/978-3-030-17184-1_14 Google ScholarGoogle ScholarCross RefCross Ref
  12. Gilad Bracha. 1992. The programming language Jigsaw: mixins, modularity and multiple inheritance. The University of Utah. Google ScholarGoogle Scholar
  13. Gilad Bracha and William Cook. 1990. Mixin-based inheritance. ACM Sigplan Notices, 25, 10 (1990), 303–311. https://doi.org/10.1145/97945.97982 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Luca Cardelli, Simone Martini, John C Mitchell, and Andre Scedrov. 1994. An extension of system F with subtyping. Information and Computation, 109, 1-2 (1994), 4–56. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Luca Cardelli and John Mitchell. 1991. Operations on Records. Mathematical Structures in Computer Science, 1 (1991), 3–48. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Luca Cardelli and Peter Wegner. 1985. On Understanding Types, Data Abstraction, and Polymorphism. ACM Comput. Surv., 17, 4 (1985), dec, 471–523. issn:0360-0300 https://doi.org/10.1145/6041.6042 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Giuseppe Castagna. 2018. Covariance and Controvariance: a fresh look at an old issue (a primer in advanced type systems for learning functional programmers). CoRR, abs/1809.01427 (2018), arXiv:1809.01427. arxiv:1809.01427 Google ScholarGoogle Scholar
  18. Giuseppe Castagna and Alain Frisch. 2005. A Gentle Introduction to Semantic Subtyping. In Proceedings of the 7th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming (PPDP ’05). Association for Computing Machinery, New York, NY, USA. 198–208. isbn:1595930906 https://doi.org/10.1145/1069774.1069793 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Giuseppe Castagna, Kim Nguyen, Zhiwu Xu, and Pietro Abate. 2015. Polymorphic Functions with Set-Theoretic Types: Part 2: Local Type Inference and Type Reconstruction. In Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’15). Association for Computing Machinery, New York, NY, USA. 289–302. isbn:9781450333009 https://doi.org/10.1145/2676726.2676991 Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Giuseppe Castagna, Kim Nguyen, Zhiwu Xu, Hyeonseung Im, Sergueï Lenglet, and Luca Padovani. 2014. Polymorphic Functions with Set-Theoretic Types: Part 1: Syntax, Semantics, and Evaluation. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’14). Association for Computing Machinery, New York, NY, USA. 5–17. isbn:9781450325448 https://doi.org/10.1145/2535838.2535840 Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Giuseppe Castagna, Tommaso Petrucciani, and Kim Nguyundefinedn. 2016. Set-Theoretic Types for Polymorphic Variants. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016). Association for Computing Machinery, New York, NY, USA. 378–391. isbn:9781450342193 https://doi.org/10.1145/2951913.2951928 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Giuseppe Castagna and Zhiwu Xu. 2011. Set-Theoretic Foundation of Parametric Polymorphism and Subtyping. In Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming (ICFP ’11). Association for Computing Machinery, New York, NY, USA. 94–106. isbn:9781450308656 https://doi.org/10.1145/2034773.2034788 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. William R. Cook and Jens Palsberg. 1989. A denotational semantics of inheritance and its correctness. In Object-Oriented Programming: Systems, Languages and Applications (OOPSLA). https://doi.org/10.1145/74878.74922 Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Mario Coppo and Mariangiola Dezani-Ciancaglini. 1978. A new type assignment for λ -terms. Archiv für mathematische Logik und Grundlagenforschung, 19, 1 (1978), 139–156. Google ScholarGoogle Scholar
  25. Mario Coppo, Mariangiola Dezani-Ciancaglini, and Betti Venneri. 1981. Functional Characters of Solvable Terms. Math. Log. Q., 27, 2-6 (1981), 45–58. https://doi.org/10.1002/malq.19810270205 Google ScholarGoogle ScholarCross RefCross Ref
  26. 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 https://doi.org/10.1145/351240.351259 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Dominic Duggan and Constantinos Sourelis. 1996. Mixin modules. ACM SIGPLAN Notices, 31, 6 (1996), 262–273. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Jana Dunfield. 2014. Elaborating intersection and union types. Journal of Functional Programming (JFP), 24, 2-3 (2014), 133–165. https://doi.org/10.1006/inco.1995.1086 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Andong Fan, Xuejing Huang, Han Xu, Yaozhu Sun, and Bruno C. d. S. Oliveira. 2022. Direct Foundations for Compositional Programming. In 36th European Conference on Object-Oriented Programming (ECOOP 2022), Karim Ali and Jan Vitek (Eds.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 222). Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl, Germany. 18:1–18:28. isbn:978-3-95977-225-9 issn:1868-8969 https://doi.org/10.4230/LIPIcs.ECOOP.2022.18 Google ScholarGoogle ScholarCross RefCross Ref
  30. Kathleen Fisher and John Reppy. 2004. A typed calculus of traits. In Electronic proceedings of FOOL. 2004. Google ScholarGoogle Scholar
  31. Matthew Flatt, Shriram Krishnamurthi, and Matthias Felleisen. 1998. Classes and mixins. In Proceedings of the 25th ACM SIGPLAN-SIGACT symposium on Principles of programming languages. 171–183. https://doi.org/10.1145/268946.268961 Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. 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, Sept., 64 pages. issn:0004-5411 https://doi.org/10.1145/1391289.1391293 Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Robert Harper and Benjamin Pierce. 1991. A record calculus based on symmetric concatenation. In Proceedings of the 18th ACM SIGPLAN-SIGACT symposium on Principles of programming languages. 131–142. https://doi.org/10.1145/99583.99603 Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Robert Harper and Benjamin Pierce. 1991. A Record Calculus Based on Symmetric Concatenation. In Proceedings of the 18th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’91). Association for Computing Machinery, New York, NY, USA. 131–142. isbn:0897914198 https://doi.org/10.1145/99583.99603 Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Xuejing Huang, Jinxu Zhao, and Bruno C. d. S. Oliveira. 2021. Taming the Merge Operator. 31 (2021), https://doi.org/10.1017/S0956796821000186 Publisher: Cambridge University Press. Google ScholarGoogle ScholarCross RefCross Ref
  36. Young Bae Jun, Hee Sik Kim, and Eun Hwan Roh. 2004. Ideal theory of subtraction algebras. Sci. Math. Jpn. Online e-2004, 397–402. Google ScholarGoogle Scholar
  37. Giovanni Lagorio, Marco Servetto, and Elena Zucca. 2009. Featherweight Jigsaw: A minimal core calculus for modular composition of classes. In European Conference on Object-Oriented Programming. 244–268. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Zhaohui Luo. 1999. Coercive Subtyping. J. Log. Comput., 9, 1 (1999), 105–130. https://doi.org/10.1093/logcom/9.1.105 Google ScholarGoogle ScholarCross RefCross Ref
  39. Koar Marntirosian, Tom Schrijvers, Bruno C. d. S. Oliveira, and Georgios Karachalias. 2020. Resolution as Intersection Subtyping via Modus Ponens. Proc. ACM Program. Lang., 4, OOPSLA (2020), Article 206, nov, https://doi.org/10.1145/3428274 Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Atsushi Ohori. 1992. A Compilation Method for ML-Style Polymorphic Record Calculi. In Proceedings of the 19th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’92). Association for Computing Machinery, New York, NY, USA. 154–165. isbn:0897914538 https://doi.org/10.1145/143165.143200 Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Atsushi Ohori. 1995. A polymorphic record calculus and its compilation. ACM Transactions on Programming Languages and Systems (TOPLAS), 17, 6 (1995), 844–895. https://doi.org/10.1145/218570.218572 Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Bruno C. d. S. Oliveira, Zhiyuan Shi, and João Alpuim. 2016. Disjoint intersection types. In International Conference on Functional Programming (ICFP). https://doi.org/10.1145/2951913.2951945 Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Benjamin C. Pierce and David N. Turner. 2000. Local Type Inference. ACM Trans. Program. Lang. Syst., 22, 1 (2000), jan, 1–44. issn:0164-0925 https://doi.org/10.1145/345099.345100 Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. François Pottier. 2000. A 3-Part Type Inference Engine. In Programming Languages and Systems, Gert Smolka (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 320–335. isbn:978-3-540-46425-9 Google ScholarGoogle ScholarCross RefCross Ref
  45. Garrel Pottinger. 1980. A type assignment for the strongly normalizable λ -terms. To HB Curry: essays on combinatory logic, lambda calculus and formalism, 561–577. Google ScholarGoogle Scholar
  46. Didier Rémy. 1990. Type inference for records in a natural extension of ML. Technical Reports (CIS), 641. Google ScholarGoogle Scholar
  47. Didier Rémy. 1995. A case study of typechecking with constrained types: Typing record concatenation. August, Presented at the workshop on Advances in types for computer science at the Newton Institute, Cambridge, UK. Google ScholarGoogle Scholar
  48. John C Reynolds. 1988. Preliminary design of the programming language Forsythe. Carnegie Mellon University. Google ScholarGoogle Scholar
  49. John C. Reynolds. 1991. The coherence of languages with intersection types. In Lecture Notes in Computer Science (LNCS). Springer Berlin Heidelberg, 675–700. Google ScholarGoogle Scholar
  50. John C Reynolds. 1997. Design of the programming language Forsythe. In ALGOL-like languages. 173–233. Google ScholarGoogle Scholar
  51. Scala Community. 2022. Tour of Scala Self-type. https://docs.scala-lang.org/tour/self-types.html Google ScholarGoogle Scholar
  52. Nathanael Schärli, Stéphane Ducasse, Oscar Nierstrasz, and Andrew P Black. 2003. Traits: Composable units of behaviour. In European Conference on Object-Oriented Programming (ECOOP). Google ScholarGoogle ScholarCross RefCross Ref
  53. Boris M Schein. 1992. Difference semigroups. Communications in algebra, 20, 8 (1992), 2153–2169. Google ScholarGoogle Scholar
  54. Mark Shields and Erik Meijer. 2001. Type-Indexed Rows. In Proceedings of the 28th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’01). Association for Computing Machinery, New York, NY, USA. 261–275. isbn:1581133367 https://doi.org/10.1145/360204.360230 Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. Pablo Tesone, Stéphane Ducasse, Guillermo Polito, Luc Fabresse, and Noury Bouraqadi. 2020. A new modular implementation for stateful traits. Science of Computer Programming, 195 (2020), 102470. Google ScholarGoogle ScholarCross RefCross Ref
  56. Philip Wadler. 1998. The expression problem. Java-genericity mailing list. Google ScholarGoogle Scholar
  57. M. Wand. 1989. Type inference for record concatenation and multiple inheritance. In [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science. 92–97. https://doi.org/10.1109/LICS.1989.39162 Google ScholarGoogle ScholarCross RefCross Ref
  58. Ningning Xie, Bruno C. d. S. Oliveira, Xuan Bi, and Tom Schrijvers. 2020. Row and Bounded Polymorphism via Disjoint Polymorphism. In 34th European Conference on Object-Oriented Programming (ECOOP 2020). https://doi.org/10.4230/LIPIcs.ECOOP.2020.27 Google ScholarGoogle ScholarCross RefCross Ref
  59. Han Xu, Xuejing Huang, and Bruno C. d. S. Oliveira. 2022. Making a Type Difference: Subtraction on Intersection Types as Generalized Record Operations (Artifact). https://doi.org/10.5281/zenodo.7472859 Google ScholarGoogle ScholarDigital LibraryDigital Library
  60. Weixin Zhang, Yaozhu Sun, and Bruno C. d. S. Oliveira. 2021. Compositional Programming. ACM Transactions on Programming Languages and Systems (TOPLAS), 43, 3 (2021), 1–61. https://doi.org/10.1145/3460228 Google ScholarGoogle ScholarDigital LibraryDigital Library
  61. Jan Zwanenburg. 1995. Record concatenation with intersection types. Eindhoven University of Technology. Google ScholarGoogle Scholar

Index Terms

  1. Making a Type Difference: Subtraction on Intersection Types as Generalized Record Operations

    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

    • Article Metrics

      • Downloads (Last 12 months)171
      • Downloads (Last 6 weeks)23

      Other Metrics

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!