Abstract
Polymorphic variants are a useful feature of the OCaml language whose current definition and implementation rely on kinding constraints to simulate a subtyping relation via unification. This yields an awkward formalization and results in a type system whose behaviour is in some cases unintuitive and/or unduly restrictive.
In this work, we present an alternative formalization of polymorphic variants, based on set-theoretic types and subtyping, that yields a cleaner and more streamlined system. Our formalization is more expressive than the current one (it types more programs while preserving type safety), it can internalize some meta-theoretic properties, and it removes some pathological cases of the current implementation resulting in a more intuitive and, thus, predictable type system. More generally, this work shows how to add full-fledged union types to functional languages of the ML family that usually rely on the Hindley-Milner type system. As an aside, our system also improves the theory of semantic subtyping, notably by proving completeness for the type reconstruction algorithm.
- V. Benzaken, G. Castagna, and A. Frisch. CDuce: an XML-centric generalpurpose language. In ACM SIGPLAN International Conference on Functional Programming (ICFP), pages 51–63, 2003. Google Scholar
Digital Library
- M. Blume, U. A. Acar, and W. Chae. Exception handlers as extensible cases. In Proceedings of the 6th Asian Symposium on Programming Languages and Systems (APLAS), LNCS, pages 273–289. Springer, 2008. Google Scholar
Digital Library
- M. Bonsangue, J. Rot, D. Ancona, F. de Boer, and J. Rutten. A coalgebraic foundation for coinductive union types. In Automata, Languages, and Programming - 41st International Colloquium (ICALP), volume 8573 of Lecture Notes in Computer Science, pages 62–73. Springer, 2014.Google Scholar
- G. Castagna and Z. Xu. Set-theoretic foundation of parametric polymorphism and subtyping. In ACM SIGPLAN International Conference on Functional Programming (ICFP), pages 94–106, 2011. Google Scholar
Digital Library
- G. Castagna, K. Nguyễn, Z. Xu, H. Im, S. Lenglet, and L. Padovani. Polymorphic functions with set-theoretic types. part 1: Syntax, semantics, and evaluation. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), pages 5–17, 2014. Google Scholar
Digital Library
- G. Castagna, K. Nguyễn, Z. Xu, and P. Abate. Polymorphic functions with set-theoretic types. part 2: Local type inference and type reconstruction. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), pages 289–302, 2015. Google Scholar
Digital Library
- G. Castagna, T. Petrucciani, and K. Nguyen. Set-theoretic types for polymorphic variants. Technical report, Université Paris Diderot, May 2016.Google Scholar
- Extended version. https://hal.archives-ouvertes.fr/view/index/docid/1325644. CDuce. http://www.cduce.org. {C AML - LIST 1}. Polymorphic variant difference. https://goo.gl/WlPgdY, May 2007. OCaml mailing list post. {C AML - LIST 2}. Variant filtering. https://goo.gl/d7DQhU, Feb. 2000.Google Scholar
- OCaml mailing list post. {C AML - LIST 3}. Polymorphic variant typing. https://goo.gl/O054v1, Feb. 2005. OCaml mailing list post. {C AML - LIST 4}. Getting rid of impossible polymorphic variant tags from inferred types. https://goo.gl/ELougz, Mar. 2004. OCaml mailing list post. R. Davies. Practical Refinement-Type Checking. PhD thesis, Carnegie Mellon University, May 2005.Google Scholar
- J. Dunfield. A Unified System of Type Refinements. PhD thesis, Carnegie Mellon University, Aug. 2007.Google Scholar
- A. Frisch, G. Castagna, and V. Benzaken. Semantic Subtyping. In LICS ’02, 17th Annual IEEE Symposium on Logic in Computer Science, pages 137–146. IEEE Computer Society Press, 2002. Google Scholar
Digital Library
- A. Frisch, G. Castagna, and V. Benzaken. Semantic subtyping: dealing set-theoretically with function, union, intersection, and negation types. Journal of the ACM, 55(4):1–67, 2008. Google Scholar
Digital Library
- J. Garrigue. Programming with polymorphic variants. In ACM SIGPLAN Workshop on ML, 1998. Informal proceedings. J. Garrigue. Simple type inference for structural polymorphism. In International Workshop on Foundations of Object-Oriented Languages (FOOL), 2002. Informal proceedings. J. Garrigue. Typing deep pattern-matching in presence of polymorphic variants. In JSSST Workshop on Programming and Programming Languages, 2004.Google Scholar
- J. Garrigue. A certified implementation of ML with structural polymorphism and recursive types. Mathematical Structures in Computer Science, 25:867–891, 2015.Google Scholar
Cross Ref
- L. Maranget. Warnings for pattern matching. Journal of Functional Programming, 17(3):387–421, 2007.Google Scholar
Cross Ref
- V. Nicollet. Do variant types in OCaml suck? http://goo.gl/FOOwal, Mar. 2011. Blog post. D. J. Pearce. Sound and complete flow typing with unions, intersections and negations. In International Conference on Verification, Model Checking, and Abstract Interpretation (VMCAI), pages 335–354, Jan. 2013. Google Scholar
Digital Library
- T. Petrucciani. A set-theoretic type system for polymorphic variants in ML. Master’s thesis, Università degli studi di Genova, 2015.Google Scholar
- B. Pierce. Programming with Intersection Types and Bounded Polymorphism. PhD thesis, Carnegie Mellon University, December 1991. Available as School of Computer Science technical report CMU-CS-91-205. F. Pottier and D. Rémy. The essence of ML type inference. In B. C. Pierce, editor, Advanced Topics in Types and Programming Languages, chapter 10, pages 389–489. MIT Press, 2005. Google Scholar
Digital Library
- J. C. Reynolds. Algol-like Languages, chapter Design of the Programming Language Forsythe, pages 173–233. Birkhäuser, Boston, MA, 1997. ISBN 978-1-4612-4118-8. Peter W. O’Hearn and Robert D. Tennent (eds.). S. Tobin-Hochstadt and M. Felleisen. The design and implementation of typed scheme. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), pages 395–406, 2008. Google Scholar
Digital Library
- S. Tobin-Hochstadt and M. Felleisen. Logical types for untyped languages. In ACM SIGPLAN International Conference on Functional Programming (ICFP), pages 117–128, 2010. Google Scholar
Digital Library
- T. Wegrzanowski. Variant types in OCaml suck. http://goo.gl/bY0bMA, May 2006. Blog post.Google Scholar
Index Terms
Set-theoretic types for polymorphic variants
Recommendations
Set-theoretic types for polymorphic variants
ICFP 2016: Proceedings of the 21st ACM SIGPLAN International Conference on Functional ProgrammingPolymorphic variants are a useful feature of the OCaml language whose current definition and implementation rely on kinding constraints to simulate a subtyping relation via unification. This yields an awkward formalization and results in a type system ...
Gradual typing with union and intersection types
We propose a type system for functional languages with gradual types and set-theoretic type connectives and prove its soundness. In particular, we show how to lift the definition of the domain and result type of an application from non-gradual types to ...
Polymorphic Functions with Set-Theoretic Types: Part 2: Local Type Inference and Type Reconstruction
POPL '15: Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming LanguagesThis article is the second part of a two articles series about the definition of higher order polymorphic functions in a type system with recursive types and set-theoretic type connectives (unions, intersections, and negations).
In the first part, ...







Comments