skip to main content
research-article
Open Access

Polymorphic symmetric multiple dispatch with variance

Published:02 January 2019Publication History
Skip Abstract Section

Abstract

Many object-oriented languages provide method overloading, which allows multiple method declarations with the same name. For a given method invocation, in order to choose what method declaration to invoke, multiple dispatch considers the run-time types of the arguments. While multiple dispatch can support binary methods (such as mathematical operators) intuitively and consistently, it is difficult to guarantee that calls will be neither ambiguous nor undefined at run time, especially in the presence of expressive language features such as multiple inheritance and parametric polymorphism. Previous efforts have formalized languages that include such features by using overloading rules that guarantee a unique and type-sound resolution of each overloaded method call; in many cases, such rules resolve ambiguity by treating the arguments asymmetrically. Here we present the first formal specification of a strongly typed object-oriented language with symmetric multiple dispatch, multiple inheritance, and parametric polymorphism with variance. We define both a static (type- checking) semantics and a dynamic (dispatching) semantics and prove the type soundness of the language, thus demonstrating that our novel dynamic dispatch algorithm is consistent with the static semantics. Details of our dynamic dispatch algorithm address certain technical challenges that arise from structural asymmetries inherent in object-oriented languages (e.g., classes typically declare ancestors explicitly but not descendants).

Skip Supplemental Material Section

Supplemental Material

a11-park.webm

References

  1. Eric Allen, David Chase, J. J. Hallett, Victor Luchangco, Jan-Willem Maessen, Sukyoung Ryu, Guy L. Steele Jr., and Sam Tobin-Hochstadt. 2008. The Fortress Language Specification Version 1.0.Google ScholarGoogle Scholar
  2. Eric Allen, J. J. Hallett, Victor Luchangco, Sukyoung Ryu, and Guy L. Steele Jr. 2007. Modular Multiple Dispatch with Multiple Inheritance. In Proceedings of the 2007 ACM Symposium on Applied Computing (SAC ’07). ACM, New York, NY, USA, 1117–1121. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Eric Allen, Justin Hilburn, Scott Kilpatrick, Victor Luchangco, Sukyoung Ryu, David Chase, and Guy L. Steele Jr. 2011. Type-checking Modular Multiple Dispatch with Parametric Polymorphism and Multiple Inheritance. In Proceedings of the ACM International Conference on Object Oriented Programming, Systems, Languages, and Applications (OOPSLA ’11). ACM, New York, NY, USA, 973–992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Jeff Bezanson, Alan Edelman, Stefan Karpinski, and Viral B. Shah. 2015. Julia: A Fresh Approach to Numerical Computing (v4). CoRR abs/1411.1607 (July 2015), 1–37. http://arxiv.org/abs/1411.1607Google ScholarGoogle Scholar
  5. Jeff Bezanson, Alan Edelman, Stefan Karpinski, and Viral B. Shah. 2017. Julia: A Fresh Approach to Numerical Computing. SIAM Rev. 59, 1 (2017), 65–98.Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. François Bourdoncle and Stephan Merz. 1997. Type Checking Higher-Order Polymorphic Multi-methods. In Proceedings of the 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’97). ACM, New York, NY, USA, 302–315. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Giuseppe Castagna, Giorgio Ghelli, and Giuseppe Longo. 1992. A Calculus for Overloaded Functions with Subtyping. In Proceedings of the 1992 ACM Conference on LISP and Functional Programming (LFP ’92). ACM, New York, NY, USA, 182–192. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Giuseppe Castagna, Giorgio Ghelli, and Giuseppe Longo. 1995. A Calculus for Overloaded Functions with Subtyping. Information and Computation 117, 1 (1995), 115–135. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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). ACM, New York, NY, USA, 289–302. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Curtis Clifton, Gary T. Leavens, Craig Chambers, and Todd Millstein. 2000. MultiJava: Modular Open Classes and Symmetric Multiple Dispatch for Java. In Proceedings of the 15th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA ’00). ACM, New York, NY, USA, 130–145. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Curtis Clifton, Todd D. Millstein, Gary T. Leavens, and Craig Chambers. 2006. MultiJava: Design Rationale, Compiler Implementation, and Applications. ACM Transactions on Programming Languages and Systems 28, 3 (May 2006), 517–575. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Devin Coughlin and Bor-Yuh Evan Chang. 2014. Fissile Type Analysis: Modular Checking of Almost Everywhere Invariants. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’14). Association for Computing Machinery, New York, 73–85. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. EPFL. 2017. A class for immutable linked lists representing ordered collections of elements of type ‘A‘ {implementation of class List for the Scala programming language}. https://github.com/scala/scala/blob/2.13.x/src/library/scala/collection/ immutable/List.scala . Accessed: 2017-11-27.Google ScholarGoogle Scholar
  14. Jacques Garrigue. 2001. Simple Type Inference for Structural Polymorphism. In Proceedings of the Second Asian Workshop on Programming Languages and Systems (APLAS’01). 329–343. Also presented as { Garrigue 2002 }.Google ScholarGoogle Scholar
  15. Jacques Garrigue. 2002. Simple Type Inference for Structural Polymorphism. In Ninth International Workshop on Foundations of Object-Oriented Languages. 1–11. http://www.cs.cmu.edu/{\char’ 176}aldrich/FOOL/papers9/garrigue.ps Also presented as { Garrigue 2001 }.Google ScholarGoogle Scholar
  16. Jacques Garrigue. 2010. A Certified Implementation of ML with Structural Polymorphism. In Programming Languages and Systems, Kazunori Ueda (Ed.). Springer Berlin Heidelberg, 360–375. LNCS 6461. Proceedings of the Eighth Asian Symposium on Programming Languages and Systems (APLAS 2010), Shanghai, China. More complete journal version is { Garrigue 2015 }. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Jacques Garrigue. 2015. A Certified Implementation of ML with Structural Polymorphism and Recursive Types. Mathematical Structures in Computer Science 25, 4 (May 2015), 867–891.Google ScholarGoogle ScholarCross RefCross Ref
  18. Atsushi Igarashi and Mirko Viroli. 2006. Variant Parametric Types: A Flexible Subtyping Scheme for Generics. ACM Transactions on Programming Languages and Systems 28, 5 (September 2006), 795–847. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Jieung Kim and Sukyoung Ryu. 2011. Coq Mechanization of Featherweight Fortress with Multiple Dispatch and Multiple Inheritance. In Certified Programs and Proofs (CPP ’11), Jean-Pierre Jouannaud and Zhong Shao (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 264–279. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Keunwoo Lee and Craig Chambers. 2006. Parameterized Modules for Classes and Extensible Functions. In ECOOP 2006 – Object-Oriented Programming, Dave Thomas (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 353–378. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Todd Millstein and Craig Chambers. 1999. Modular Statically Typed Multimethods. In ECOOP’ 99 — Object-Oriented Programming, Rachid Guerraoui (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 279–303. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Todd Millstein and Craig Chambers. 2002. Modular Statically Typed Multimethods. Information and Computation 175, 1 (2002), 76 – 118.Google ScholarGoogle ScholarCross RefCross Ref
  23. Todd David Millstein. 2003. Reconciling Software Extensibility with Modular Program Reasoning. Ph.D. Dissertation. University of Washington.Google ScholarGoogle Scholar
  24. Martin Odersky, Lex Spoon, and Bill Venners. 2016. Programming in Scala (3rd ed.). Artima Press, Walnut Creek, California, USA. ISBN 978-0981531687.Google ScholarGoogle Scholar
  25. Gyunghee Park, Jaemin Hong, Guy L. Steele Jr., and Sukyoung Ryu. 2018. Polymorphic Symmetric Multiple Dispatch with Variance (Extended Report).Google ScholarGoogle Scholar
  26. Guy Steele and David Chase. 2012. Personal communication.Google ScholarGoogle Scholar
  27. Guy L. Steele Jr. 2017. It’s Time for a New Old Language. Published on YouTube. https://youtu.be/7HKbjYqqPPQ Video (TRT 1:12:11) of invited keynote talk at PPoPP ’17: 22nd ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, Austin, Texas, February 6, 2017. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. S. Tucker Taft. 2011. Multicore Programming in ParaSail: Parallel Specification and Implementation Language. In Proceedings of the 16th Ada-Europe International Conference on Reliable Software Technologies (Ada-Europe’11). Springer-Verlag, Berlin, Heidelberg, 196–200. http://dl.acm.org/citation.cfm?id=2018027.2018049 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. S. Tucker Taft. 2016. Designing ParaSail, a new programming language (blog). http://parasail- programming- language. blogspot.com . Accessed: 2018-04-09.Google ScholarGoogle Scholar
  30. Dimitrios Vytiniotis, Simon Peyton Jones, Koen Claessen, and Dan Rosén. 2013. HALO: Haskell to Logic through Denotational Semantics. In Proceedings of the 40th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’13). Association for Computing Machinery, New York, 431–442. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Yanlin Wang, Haoyuan Zhang, Bruno C. d. S. Oliveira, and Marco Servetto. 2018. FHJ: A Formal Model for Hierarchical Dispatching and Overriding. In 32nd European Conference on Object-Oriented Programming, ECOOP 2018, July 16-21, 2018, Amsterdam, The Netherlands. 20:1–20:30.Google ScholarGoogle Scholar
  32. Andrew K. Wright and Matthias Felleisen. 1994. A Syntactic Approach to Type Soundness. Information and Computation 115, 1 (Nov. 1994), 38–94. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Polymorphic symmetric multiple dispatch with variance

      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
      About Cookies On This Site

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

      Learn more

      Got it!