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.
Supplemental Material
- 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 Scholar
- 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 Scholar
- Franz Baader and Tobias Nipkow. 1998. Term Rewriting and All That. Cambridge University Press.Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Luis Damas and Robin Milner. 1982. Principal Type-schemes for Functional Programs. In Symposium on Principles of Programming Languages (POPL ’82). ACM.Google Scholar
- Atze Dijkstra. 2005. Stepping through Haskell. Ph.D. Dissertation. Universiteit Utrecht.Google Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Richard A. Eisenberg. 2016. Dependent Types in Haskell: Theory and Practice. Ph.D. Dissertation. University of Pennsylvania.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Richard A. Eisenberg and Stephanie Weirich. 2012. Dependently Typed Programming with Singletons. In ACM SIGPLAN Haskell Symposium.Google Scholar
- 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 Scholar
- Adam Gundry. 2013. Type Inference, Haskell and Dependent Types. Ph.D. Dissertation. University of Strathclyde.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- J. Roger Hindley. 1969. The Principal Type-Scheme of an Object in Combinatory Logic. Trans. Amer. Math. Soc., 146 (1969).Google Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Daan Leijen. 2006. First-class polymorphism with existential types. Unpublished.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- Robin Milner. 1978. A Theory of Type Polymorphism in Programming. J. Comput. System Sci., 17 (1978).Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- Martin Odersky and Konstantin Läufer. 1996. Putting Type Annotations to Work. In Symposium on Principles of Programming Languages (POPL ’96). ACM.Google Scholar
Digital Library
- Nigel Perry. 1991. The implementation of practical functional programming languages. Ph.D. Dissertation. Imperial College of Science, Technology and Medicine, University of London.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
- Benjamin C. Pierce. 2002. Types and Programming Languages. MIT Press, Cambridge, MA.Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Andreas Rossberg, Claudio Russo, and Derek Dreyer. 2014. F-ing modules. Journal of functional programming, 24, 5 (2014), 529–607.Google Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
- Stephanie Weirich. 2018. Dependent Types in Haskell. Haskell eXchange keynote.Google Scholar
- 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 Scholar
Digital Library
- Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded recursive datatype constructors. In Principles of Programming Languages (POPL ’03). ACM.Google Scholar
Index Terms
An existential crisis resolved: type inference for first-class existential types
Recommendations
Type checking and inference for polymorphic and existential types
CATS '09: Proceedings of the Fifteenth Australasian Symposium on Computing: The Australasian Theory - Volume 94This paper proves undecidability of type checking and type inference problems in some variants of typed lambda calculi with polymorphic and existential types. First, type inference in the domain-free polymorphic lambda calculus is proved to be ...
Type inference for unboxed types and first class mutability
PLOS '06: Proceedings of the 3rd workshop on Programming languages and operating systems: linguistic support for modern operating systemsSystems programs rely on fine-grain control of data representation and use of state to achieve performance, conformance to hard-ware specification, and temporal predictability. The robustness and checkability of these programs could be greatly improved ...
Type checking and inference are equivalent in lambda calculi with existential types
WFLP'09: Proceedings of the 18th international conference on Functional and Constraint Logic ProgrammingThis paper shows that type-checking and type-inference problems are equivalent in domain-free lambda calculi with existential types, that is, type-checking problem is Turing reducible to type-inference problem and vice versa. In this paper, the ...






Comments