skip to main content
article

Set-theoretic types for polymorphic variants

Published:04 September 2016Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle Scholar
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. G. Castagna, T. Petrucciani, and K. Nguyen. Set-theoretic types for polymorphic variants. Technical report, Université Paris Diderot, May 2016.Google ScholarGoogle Scholar
  8. 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 ScholarGoogle Scholar
  9. 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 ScholarGoogle Scholar
  10. J. Dunfield. A Unified System of Type Refinements. PhD thesis, Carnegie Mellon University, Aug. 2007.Google ScholarGoogle Scholar
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle Scholar
  14. J. Garrigue. A certified implementation of ML with structural polymorphism and recursive types. Mathematical Structures in Computer Science, 25:867–891, 2015.Google ScholarGoogle ScholarCross RefCross Ref
  15. L. Maranget. Warnings for pattern matching. Journal of Functional Programming, 17(3):387–421, 2007.Google ScholarGoogle ScholarCross RefCross Ref
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. T. Petrucciani. A set-theoretic type system for polymorphic variants in ML. Master’s thesis, Università degli studi di Genova, 2015.Google ScholarGoogle Scholar
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. T. Wegrzanowski. Variant types in OCaml suck. http://goo.gl/bY0bMA, May 2006. Blog post.Google ScholarGoogle Scholar

Index Terms

  1. Set-theoretic types for polymorphic variants

    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 ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 51, Issue 9
      ICFP '16
      September 2016
      501 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/3022670
      Issue’s Table of Contents
      • cover image ACM Conferences
        ICFP 2016: Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming
        September 2016
        501 pages
        ISBN:9781450342193
        DOI:10.1145/2951913

      Copyright © 2016 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 4 September 2016

      Check for updates

      Qualifiers

      • 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!