skip to main content
research-article

Sums of uncertainty: refinements go gradual

Published:01 January 2017Publication History
Skip Abstract Section

Abstract

A long-standing shortcoming of statically typed functional languages is that type checking does not rule out pattern-matching failures (run-time match exceptions). Refinement types distinguish different values of datatypes; if a program annotated with refinements passes type checking, pattern-matching failures become impossible. Unfortunately, refinement is a monolithic property of a type, exacerbating the difficulty of adding refinement types to nontrivial programs.

Gradual typing has explored how to incrementally move between static typing and dynamic typing. We develop a type system of gradual sums that combines refinement with imprecision. Then, we develop a bidirectional version of the type system, which rules out excessive imprecision, and give a type-directed translation to a target language with explicit casts. We prove that the static sublanguage cannot have match failures, that a well-typed program remains well-typed if its type annotations are made less precise, and that making annotations less precise causes target programs to fail later. Several of these results correspond to criteria for gradual typing given by Siek et al. (2015).

Skip Supplemental Material Section

Supplemental Material

References

  1. Martín Abadi, Luca Cardelli, Benjamin Pierce, and Gordon Plotkin. Dynamic typing in a statically typed language. ACM Trans. Prog. Lang. Syst., 13(2):237–268, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Amal Ahmed, Robert Bruce Findler, Jeremy G. Siek, and Philip Wadler. Blame for all. In Principles of Programming Languages, pages 201–214, 2011.Google ScholarGoogle Scholar
  3. Esteban Allende, Johan Fabry, Ronald Garcia, and Éric Tanter. Confined gradual typing. In OOPSLA, pages 251–270, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Felipe Bañados Schwerter, Ronald Garcia, and Éric Tanter. A theory of gradual effect systems. In ICFP, pages 283–295, 2014.Google ScholarGoogle Scholar
  5. Thierry Coquand. An algorithm for type-checking dependent types. Science of Computer Programming, 26(1–3):167–177, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Rowan Davies. Practical Refinement-Type Checking. PhD thesis, Carnegie Mellon University, 2005. CMU-CS-05-110. Rowan Davies and Frank Pfenning. Intersection types and computational effects. In ICFP, pages 198–208, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Michael Dummett. The Logical Basis of Metaphysics. Harvard University Press, 1991. The William James Lectures, 1976.Google ScholarGoogle Scholar
  8. Jana Dunfield. A Unified System of Type Refinements. PhD thesis, Carnegie Mellon University, 2007. CMU-CS-07-129. Jana Dunfield. Elaborating evaluation-order polymorphism. In Int'l Conf. Functional Programming, 2015. arXiv:1504.07680 {cs.PL}. Jana Dunfield and Neelakantan R. Krishnaswami. Complete and easy bidirectional typechecking for higher-rank polymorphism. In ICFP, 2013. arXiv:1306.6032 {cs.PL}. Jana Dunfield and Frank Pfenning. Tridirectional typechecking. In Principles of Programming Languages, pages 281-292, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Tim Freeman. Refinement Types for ML. PhD thesis, Carnegie Mellon University, 1994. CMU-CS-94-110. Tim Freeman and Frank Pfenning. Refinement types for ML. In Programming Language Design and Implementation, pages 268–277, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Ronald Garcia and Matteo Cimini. Principal type schemes for gradual programs. In Principles of Programming Languages, pages 303–315, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Ronald Garcia, Alison M. Clark, and Éric Tanter. Abstracting gradual typing. In Principles of Programming Languages, pages 429–442, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Gerhard Gentzen. Untersuchungen über das logische Schließen. Mathematische Zeitschrift, 39:176–210, 405–431, 1934. English translation, Investigations into logical deduction, in M. Szabo, editor, Collected papers of Gerhard Gentzen (North-Holland, 1969), pages 68–131. Ruud Koot and Jurriaan Hage. Type-based exception analysis for non-strict higher-order functional languages with imprecise exception semantics. In Proceedings of the 2015 Workshop on Partial Evaluation and Program Manipulation, pages 127–138, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Per Martin-Löf. On the meanings of the logical constants and the justifications of the logical laws. Nordic Journal of Philosophical Logic, 1(1):11–60, 1996. Notes for lectures given in 1983 in Siena, Italy. Trevor L. McDonell, Timothy A. K. Zakian, Matteo Cimini, and Ryan R. Newton. Ghostbuster: A tool for simplifying and converting GADTs. In ICFP, pages 338–350, 2016.Google ScholarGoogle Scholar
  14. Robin Milner, Mads Tofte, Robert Harper, and David MacQueen. The Definition of Standard ML (Revised). MIT Press, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Frank Pfenning. Lecture notes on harmony. Lecture notes for 15–317: Constructive Logic, Carnegie Mellon University, September 2009.Google ScholarGoogle Scholar
  16. www.cs.cmu.edu/ ∼fp/courses/15317f09/lectures/03-harmony.pdf. Frank Pfenning and Rowan Davies. A judgmental reconstruction of modal logic. Mathematical Structures in Computer Science, 11(4):511–540, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Brigitte Pientka. A type-theoretic foundation for programming with higher-order abstract syntax and first-class substitutions. In Principles of Programming Languages, pages 371–382, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Brigitte Pientka and Jana Dunfield. Beluga: A framework for programming and reasoning with deductive systems (system description). In Int?l Joint Conference on Automated Reasoning (IJCAR), pages 15?21, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Benjamin C. Pierce and David N. Turner. Local type inference. In Principles of Programming Languages, pages 252–265, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Full version in ACM Trans. Prog. Lang. Sys., 22(1):1–44, 2000.Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Dag Prawitz. Natural Deduction. Almqvist & Wiksells, 1965.Google ScholarGoogle Scholar
  22. Jeremy Siek and Walid Taha. Gradual typing for objects. In European Conference on Object-Oriented Programming, pages 2–27. Springer, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Jeremy G. Siek and Walid Taha. Gradual typing for functional languages. In Proceedings of the Scheme and Functional Programming Workshop, pages 81–92, September 2006.Google ScholarGoogle Scholar
  24. Jeremy G. Siek and Manish Vachharajani. Gradual typing with unification-based inference. In Symposium on Dynamic Languages (DLS), pages 7:1–7:12, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, and John Tang Boyland. Refined criteria for gradual typing. In LIPIcs-Leibniz International Proceedings in Informatics, volume 32. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2015.Google ScholarGoogle Scholar
  26. Philip Wadler and Robert Bruce Findler. Well-typed programs can’t be blamed. In European Symposium on Programming, pages 1– 16, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Hongwei Xi and Frank Pfenning. Dependent types in practical programming. In Principles of Programming Languages, pages 214–227, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Sums of uncertainty: refinements go gradual

      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 52, Issue 1
        POPL '17
        January 2017
        901 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/3093333
        Issue’s Table of Contents
        • cover image ACM Conferences
          POPL '17: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages
          January 2017
          901 pages
          ISBN:9781450346603
          DOI:10.1145/3009837

        Copyright © 2017 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 1 January 2017

        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!