skip to main content
research-article
Open Access
Distinguished Paper

An existential crisis resolved: type inference for first-class existential types

Published:19 August 2021Publication History
Skip Abstract Section

Abstract

Despite the great success of inferring and programming with universal types, their dual—existential types—are much harder to work with. Existential types are useful in building abstract types, working with indexed types, and providing first-class support for refinement types. This paper, set in the context of Haskell, presents a bidirectional type-inference algorithm that infers where to introduce and eliminate existentials without any annotations in terms, along with an explicitly typed, type-safe core language usable as a compilation target. This approach is backward compatible. The key ingredient is to use strong existentials, which support (lazily) projecting out the encapsulated data, not weak existentials accessible only by pattern-matching.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

Despite the great success of inferring and programming with universal types, their dual—existential types—are much harder to work with. Existential types are useful in building abstract types, working with indexed types, and providing first-class support for refinement types. This paper, set in the context of Haskell, presents a bidirectional type-inference algorithm that infers where to introduce and eliminate existentials without any annotations in terms, along with an explicitly typed, type-safe core language usable as a compilation target. This approach is backward compatible. The key ingredient is to use strong existentials, which support (lazily) projecting out the encapsulated data, not weak existentials accessible only by pattern-matching.

3473569.mp4

Presentation Videos

References

  1. Lennart Augustsson. 1994. Haskell B. user’s manual. https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.50.5800&rep=rep1&type=pdfGoogle ScholarGoogle Scholar
  2. Lennart Augustsson and Magnus Carlsson. 1999. An exercise in dependent types: A well-typed interpreter. http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.39.2895&rep=rep1&type=pdf Unpublished manuscript.Google ScholarGoogle Scholar
  3. Franz Baader and Tobias Nipkow. 1998. Term Rewriting and All That. Cambridge University Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Gert-Jan Bottu and Richard A. Eisenberg. 2021. Seeking Stability by being Lazy and Shallow: Lazy and shallow instantiation is user friendly. In ACM SIGPLAN Haskell Symposium.Google ScholarGoogle Scholar
  5. Luca Cardelli and Xavier Leroy. 1990. Abstract types and the dot notation. In IFIP TC2 working conference on programming concepts and methods. 479–504.Google ScholarGoogle Scholar
  6. Dominique Clément, Thierry Despeyroux, Gilles Kahn, and Joëlle Despeyroux. 1986. A Simple Applicative Language: Mini-ML. In Conference on LISP and Functional Programming (LFP ’86). ACM.Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Karl Crary. 2017. Modules, Abstraction, and Parametric Polymorphism. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017). Association for Computing Machinery, New York, NY, USA. 100–113. isbn:9781450346603 https://doi.org/10.1145/3009837.3009892 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Luis Damas and Robin Milner. 1982. Principal Type-schemes for Functional Programs. In Symposium on Principles of Programming Languages (POPL ’82). ACM.Google ScholarGoogle Scholar
  9. Atze Dijkstra. 2005. Stepping through Haskell. Ph.D. Dissertation. Universiteit Utrecht.Google ScholarGoogle Scholar
  10. Jana Dunfield and Neelakantan R. Krishnaswami. 2013. Complete and Easy Bidirectional Typechecking for Higher-rank Polymorphism. In International Conference on Functional Programming (ICFP ’13). ACM.Google ScholarGoogle Scholar
  11. Jana Dunfield and Neelakantan R. Krishnaswami. 2019. Sound and Complete Bidirectional Typechecking for Higher-Rank Polymorphism with Existentials and Indexed Types. Proc. ACM Program. Lang., 3, POPL (2019), Article 9, Jan., 28 pages. https://doi.org/10.1145/3290322 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Richard A. Eisenberg. 2016. Dependent Types in Haskell: Theory and Practice. Ph.D. Dissertation. University of Pennsylvania.Google ScholarGoogle Scholar
  13. Richard A. Eisenberg. 2020. Stitch: The Sound Type-Indexed Type Checker (Functional Pearl). In Proceedings of the 13th ACM SIGPLAN International Symposium on Haskell (Haskell 2020). Association for Computing Machinery, New York, NY, USA. 39–53. isbn:9781450380508 https://doi.org/10.1145/3406088.3409015 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Richard A. Eisenberg, Joachim Breitner, and Simon Peyton Jones. 2018. Type Variables in Patterns. In Proceedings of the 11th ACM SIGPLAN International Symposium on Haskell (Haskell 2018). Association for Computing Machinery, New York, NY, USA. 94–105. isbn:9781450358354 https://doi.org/10.1145/3242744.3242753 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Richard A. Eisenberg and Stephanie Weirich. 2012. Dependently Typed Programming with Singletons. In ACM SIGPLAN Haskell Symposium.Google ScholarGoogle Scholar
  16. Jean-Yves Girard. 1972. Interprétation fonctionnelle et élimination des coupures de l’arithmétique d’ordre supérieur. Ph.D. Dissertation. Université Paris 7.Google ScholarGoogle Scholar
  17. Adam Gundry. 2013. Type Inference, Haskell and Dependent Types. Ph.D. Dissertation. University of Strathclyde.Google ScholarGoogle Scholar
  18. Cordelia V. Hall, Kevin Hammond, Simon L. Peyton Jones, and Philip L. Wadler. 1996. Type Classes in Haskell. ACM Trans. Program. Lang. Syst., 18, 2 (1996), March.Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Robert Harper and Benjamin C. Pierce. 2005. Design Considerations for ML-Style Module Systems. In Advanced Topics in Types and Programming Languages, Benjamin C. Pierce (Ed.). The MIT Press, 293–346.Google ScholarGoogle Scholar
  20. J. Roger Hindley. 1969. The Principal Type-Scheme of an Object in Combinatory Logic. Trans. Amer. Math. Soc., 146 (1969).Google ScholarGoogle Scholar
  21. William Alvin Howard. 1969. The Formulae-as-types Notion of Construction. https://www.dcc.fc.up.pt/~acm/howard2.pdf Dedicated to H. B. Curry on the occasion of his 80th birthday.Google ScholarGoogle Scholar
  22. Mark P. Jones. 1992. A Theory of Qualified Types. In Proceedings of the 4th European Symposium on Programming (ESOP ’92). Springer-Verlag, Berlin, Heidelberg. 287–306. isbn:3540552537Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Konstantin Läufer. 1996. Type classes with existential types. Journal of Functional Programming, 6, 3 (1996), 485–518. https://doi.org/10.1017/S0956796800001817 Google ScholarGoogle ScholarCross RefCross Ref
  24. Konstantin Läufer and Martin Odersky. 1994. Polymorphic type inference and abstract data types. ACM Transactions on Programming Languages and Systems (TOPLAS), 16, 5 (1994), 1411–1430.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Didier Le Botlan and Didier Rémy. 2003. ML^F: Raising ML to the power of System F. In International Conference on Functional Programming. ACM.Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Daan Leijen. 2006. First-class polymorphism with existential types. Unpublished.Google ScholarGoogle Scholar
  27. David B MacQueen. 1986. Using dependent types to express modular structure. In Proceedings of the 13th ACM SIGACT-SIGPLAN symposium on Principles of programming languages. 277–286.Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Per Martin-Löf. 1975. An intuitionistic theory of types: Predicative part. In Studies in Logic and the Foundations of Mathematics. 80, Elsevier, 73–118.Google ScholarGoogle Scholar
  29. Conor Thomas McBride. 2014. How to Keep Your Neighbours in Order. In Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming (ICFP ’14). ACM.Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Robin Milner. 1978. A Theory of Type Polymorphism in Programming. J. Comput. System Sci., 17 (1978).Google ScholarGoogle Scholar
  31. John C Mitchell and Gordon D Plotkin. 1988. Abstract types have existential type. ACM Transactions on Programming Languages and Systems (TOPLAS), 10, 3 (1988), 470–502.Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Stefan Monnier and David Haguenauer. 2010. Singleton types here, singleton types there, singleton types everywhere. In Programming languages meets program verification (PLPV ’10). ACM.Google ScholarGoogle Scholar
  33. Benoît Montagu and Didier Rémy. 2009. Modeling Abstract Types in Modules with Open Existential Types. In Proceedings of the 36th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’09). Association for Computing Machinery, New York, NY, USA. 354–365. isbn:9781605583792 https://doi.org/10.1145/1480881.1480926 Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Koji Nakazawa and Makoto Tatsuta. 2009. Type Checking and Inference for Polymorphic and Existential Types. In Proceedings of the Fifteenth Australasian Symposium on Computing: The Australasian Theory - Volume 94 (CATS ’09). Australian Computer Society, Inc., AUS. 63–72. isbn:9781920682750Google ScholarGoogle Scholar
  35. Koji Nakazawa, Makoto Tatsuta, Yukiyoshi Kameyama, and Hiroshi Nakano. 2008. Undecidability of Type-Checking in Domain-Free Typed Lambda-Calculi with Existence. In Computer Science Logic, Michael Kaminski and Simone Martini (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 478–492. isbn:978-3-540-87531-4Google ScholarGoogle Scholar
  36. Martin Odersky and Konstantin Läufer. 1996. Putting Type Annotations to Work. In Symposium on Principles of Programming Languages (POPL ’96). ACM.Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Nigel Perry. 1991. The implementation of practical functional programming languages. Ph.D. Dissertation. Imperial College of Science, Technology and Medicine, University of London.Google ScholarGoogle Scholar
  38. Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Mark Shields. 2007. Practical type inference for arbitrary-rank types. Journal of Functional Programming, 17, 1 (2007), Jan..Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. F. Pfenning. 1991. Unification and anti-unification in the calculus of constructions. In Proceedings 1991 Sixth Annual IEEE Symposium on Logic in Computer Science. IEEE Computer Society, Los Alamitos, CA, USA. 74,75,76,77,78,79,80,81,82,83,84,85. https://doi.org/10.1109/LICS.1991.151632 Google ScholarGoogle ScholarCross RefCross Ref
  40. Frank Pfenning and Peter Lee. 1989. LEAP: A language with eval and polymorphism. In TAPSOFT ’89, J. Díaz and F. Orejas (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 345–359. isbn:978-3-540-46118-0Google ScholarGoogle Scholar
  41. Benjamin C. Pierce. 2002. Types and Programming Languages. MIT Press, Cambridge, MA.Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. François Pottier and Didier Rémy. 2005. The Essence of ML Type Inference. In Advanced Topics in Types and Programming Languages, Benjamin C. Pierce (Ed.). The MIT Press, 387–489.Google ScholarGoogle Scholar
  43. John C. Reynolds. 1974. Towards a theory of type structure. In Programming Symposium, B. Robinet (Ed.) (Lecture Notes in Computer Science, Vol. 19). Springer Berlin Heidelberg, 408–425.Google ScholarGoogle ScholarCross RefCross Ref
  44. Andreas Rossberg. 2015. 1ML – Core and Modules United (F-Ing First-Class Modules). In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming (ICFP 2015). Association for Computing Machinery, New York, NY, USA. 35–47. isbn:9781450336697 https://doi.org/10.1145/2784731.2784738 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Andreas Rossberg, Claudio Russo, and Derek Dreyer. 2014. F-ing modules. Journal of functional programming, 24, 5 (2014), 529–607.Google ScholarGoogle ScholarCross RefCross Ref
  46. Alejandro Serrano, Jurriaan Hage, Simon Peyton Jones, and Dimitrios Vytiniotis. 2020. A Quick Look at Impredicativity. Proc. ACM Program. Lang., 4, ICFP (2020), Article 89, Aug., 29 pages. https://doi.org/10.1145/3408971 Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Martin Sulzmann, Manuel M. T. Chakravarty, Simon Peyton Jones, and Kevin Donnelly. 2007. System F with type equality coercions. In Types in languages design and implementation (TLDI ’07). ACM.Google ScholarGoogle Scholar
  48. Ross Tate, Juan Chen, and Chris Hawblitzel. 2008. A Flexible Framework for Type Inference with Existential Quantification. https://www.microsoft.com/en-us/research/publication/a-flexible-framework-for-type-inference-with-existential-quantification/Google ScholarGoogle Scholar
  49. Niki Vazou, Eric L. Seidel, Ranjit Jhala, Dimitrios Vytiniotis, and Simon Peyton Jones. 2014. Refinement Types for Haskell. In International Conference on Functional Programming (ICFP ’14). ACM.Google ScholarGoogle Scholar
  50. Stephanie Weirich. 2018. Dependent Types in Haskell. Haskell eXchange keynote.Google ScholarGoogle Scholar
  51. Stephanie Weirich, Antoine Voizard, Pedro Henrique Azevedo de Amorim, and Richard A. Eisenberg. 2017. A Specification for Dependent Types in Haskell. Proc. ACM Program. Lang., 1, ICFP (2017), Article 31, Aug., 29 pages. issn:2475-1421 https://doi.org/10.1145/3110275 Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded recursive datatype constructors. In Principles of Programming Languages (POPL ’03). ACM.Google ScholarGoogle Scholar

Index Terms

  1. An existential crisis resolved: type inference for first-class existential types

      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

      • Published in

        cover image Proceedings of the ACM on Programming Languages
        Proceedings of the ACM on Programming Languages  Volume 5, Issue ICFP
        August 2021
        1011 pages
        EISSN:2475-1421
        DOI:10.1145/3482883
        Issue’s Table of Contents

        Copyright © 2021 Owner/Author

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 19 August 2021
        Published in pacmpl Volume 5, Issue ICFP

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

      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!