Abstract
MLsub extends traditional Hindley-Milner type inference with subtyping while preserving compact principal types, an exciting new development. However, its specification in terms of biunification is difficult to understand, relying on the new concepts of bisubstitution and polar types, and making use of advanced notions from abstract algebra. In this paper, we show that these are in fact not essential to understanding the mechanisms at play in MLsub. We propose an alternative algorithm called Simple-sub, which can be implemented efficiently in under 500 lines of code (including parsing, simplification, and pretty-printing), looks more familiar, and is easier to understand.
We present an experimental evaluation of Simple-sub against MLsub on a million randomly-generated well-scoped expressions, showing that the two systems agree. The mutable automaton-based implementation of MLsub is quite far from its algebraic specification, leaving a lot of space for errors; in fact, our evaluation uncovered several bugs in it. We sketch more straightforward soundness and completeness arguments for Simple-sub, based on a syntactic specification of the type system.
This paper is meant to be light in formalism, rich in insights, and easy to consume for prospective designers of new type systems and programming languages. In particular, no abstract algebra is inflicted on readers.
Supplemental Material
- Roberto M. Amadio and Luca Cardelli. 1993. Subtyping Recursive Types. ACM Trans. Program. Lang. Syst. 15, 4 (Sept. 1993 ), 575-631. https://doi.org/10.1145/155183.155231 Google Scholar
Digital Library
- Nada Amin, Samuel Grütter, Martin Odersky, Tiark Rompf, and Sandro Stucki. 2016. The Essence of Dependent Object Types. Springer International Publishing, Cham, 249-272. https://doi.org/10.1007/978-3-319-30936-1_14 Google Scholar
- Andrew W. Appel, Paul-André Melliès, Christopher D. Richards, and Jérôme Vouillon. 2007. A Very Modal Model of a Modern, Major, General Type System. In Proceedings of the 34th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Nice, France) (POPL '07). Association for Computing Machinery, New York, NY, USA, 109-122. https://doi.org/10.1145/1190216.1190235 Google Scholar
Digital Library
- Giuseppe Castagna, Tommaso Petrucciani, and Kim Nguyen. 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, Nara, Japan, 378-391. https://doi.org/10.1145/2951913.2951928 Google Scholar
Digital Library
- Nathanaël Courant. 2018. Safely typing algebraic efects (Gagallium Blog). http://gallium.inria.fr/blog/safely-typingalgebraic-efects/. Accessed: 2020-06-30.Google Scholar
- Luis Damas and Robin Milner. 1982. Principal type-schemes for functional programs. In Proceedings of the 9th ACM SIGPLAN-SIGACT symposium on Principles of programming languages (POPL '82). Association for Computing Machinery, Albuquerque, New Mexico, 207-212. https://doi.org/10.1145/582153.582176 Google Scholar
Digital Library
- Stephen Dolan. 2017. Algebraic subtyping. Ph.D. Dissertation.Google Scholar
- Stephen Dolan and Alan Mycroft. 2017. Polymorphism, subtyping, and type inference in MLsub. ACM SIGPLAN Notices 52, 1 (Jan. 2017 ), 60-72. https://doi.org/10.1145/3093333.3009882 Google Scholar
Digital Library
- Joshua Dunfield and Neelakantan R. Krishnaswami. 2013. Complete and Easy Bidirectional Typechecking for Higher-Rank Polymorphism. SIGPLAN Not. 48, 9 (Sept. 2013 ), 429-442. https://doi.org/10.1145/2544174.2500582 Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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, Article 19 ( Sept. 2008 ), 64 pages. https://doi.org/10. 1145/1391289.1391293 Google Scholar
Digital Library
- Jacques Garrigue. 1998. Programming with polymorphic variants. In ML Workshop, Vol. 13. Baltimore, 7.Google Scholar
- Roger Hindley. 1969. The Principal Type-Scheme of an Object in Combinatory Logic. Trans. Amer. Math. Soc. 146 ( 1969 ), 29-60. https://doi.org/10.2307/1995158 Publisher: American Mathematical Society. Google Scholar
Cross Ref
- Haruo Hosoya, Jérôme Vouillon, and Benjamin C. Pierce. 2005. Regular Expression Types for XML. ACM Trans. Program. Lang. Syst. 27, 1 (Jan. 2005 ), 46-90. https://doi.org/10.1145/1053468.1053470 Google Scholar
Digital Library
- DeLesley S. Hutchins. 2010. Pure Subtype Systems. In Proceedings of the 37th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Madrid, Spain) (POPL '10). Association for Computing Machinery, New York, NY, USA, 287-298. https://doi.org/10.1145/1706299.1706334 Google Scholar
Digital Library
- Oleg Kiselyov. 2013. Eficient generalization with levels (Okmij Blog). http://okmij.org/ftp/ML/generalization.html#levels. Accessed: 2020-06-30.Google Scholar
- Robin Milner. 1978. A theory of type polymorphism in programming. J. Comput. System Sci. 17, 3 (Dec. 1978 ), 348-375. https://doi.org/10.1016/ 0022-0000 ( 78 ) 90014-4 Google Scholar
Cross Ref
- Martin Odersky and Konstantin Läufer. 1996. Putting Type Annotations to Work. In Proceedings of the 23rd ACM SIGPLANSIGACT Symposium on Principles of Programming Languages (St. Petersburg Beach, Florida, USA) ( POPL '96). Association for Computing Machinery, New York, NY, USA, 54-67. https://doi.org/10.1145/237721.237729 Google Scholar
Digital Library
- David J. Pearce. 2013. Sound and Complete Flow Typing with Unions, Intersections and Negations. In Verification, Model Checking, and Abstract Interpretation (Lecture Notes in Computer Science), Roberto Giacobazzi, Josh Berdine, and Isabella Mastroeni (Eds.). Springer, Berlin, Heidelberg, 335-354. https://doi.org/10.1007/978-3-642-35873-9_21 Google Scholar
Digital Library
- Benjamin C. Pierce. 2002. Types and programming languages. MIT press.Google Scholar
Digital Library
- François Pottier. 1998. Type Inference in the Presence of Subtyping: from Theory to Practice. Research Report RR-3483. INRIA. https://hal.inria.fr/inria-00073205Google Scholar
- Patrick M. Rondon, Ming Kawaguci, and Ranjit Jhala. 2008. Liquid Types. In Proceedings of the 29th ACM SIGPLAN Conference on Programming Language Design and Implementation (Tucson, AZ, USA) ( PLDI '08). Association for Computing Machinery, New York, NY, USA, 159-169. https://doi.org/10.1145/1375581.1375602 Google Scholar
Digital Library
- 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 (Vancouver, BC, Canada) ( ICFP 2015 ). Association for Computing Machinery, New York, NY, USA, 35-47. https://doi.org/10.1145/2784731.2784738 Google Scholar
Digital Library
- John Rushby, Sam Owre, and Natarajan Shankar. 1998. Subtypes for Specifications: Predicate Subtyping in PVS. IEEE Trans. Softw. Eng. 24, 9 (Sept. 1998 ), 709-720. https://doi.org/10.1109/32.713327 Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. 2010. Logical Types for Untyped Languages. SIGPLAN Not. 45, 9 (Sept. 2010 ), 117-128. https://doi.org/10.1145/1932681.1863561 Google Scholar
Digital Library
- Niki Vazou, Eric L. Seidel, Ranjit Jhala, Dimitrios Vytiniotis, and Simon Peyton-Jones. 2014. Refinement Types for Haskell. In Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming (Gothenburg, Sweden) (ICFP '14). Association for Computing Machinery, New York, NY, USA, 269-282. https://doi.org/10.1145/2628136.2628161 Google Scholar
Digital Library
Index Terms
The simple essence of algebraic subtyping: principal type inference with subtyping made easy (functional pearl)
Recommendations
Polymorphism, subtyping, and type inference in MLsub
POPL '17: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming LanguagesWe present a type system combining subtyping and ML-style parametric polymorphism. Unlike previous work, our system supports type inference and has compact principal types. We demonstrate this system in the minimal language MLsub, which types a strict ...
Polymorphism, subtyping, and type inference in MLsub
POPL '17We present a type system combining subtyping and ML-style parametric polymorphism. Unlike previous work, our system supports type inference and has compact principal types. We demonstrate this system in the minimal language MLsub, which types a strict ...
Subtyping delimited continuations
ICFP '11: Proceedings of the 16th ACM SIGPLAN international conference on Functional programmingWe present a type system with subtyping for first-class delimited continuations that generalizes Danvy and Filinski's type system for shift and reset by maintaining explicit information about the types of contexts in the metacontext. We exploit this ...






Comments