skip to main content
article
Public Access

Principal type inference for GADTs

Published:11 January 2016Publication History
Skip Abstract Section

Abstract

We present a new method for GADT type inference that improves the precision of previous approaches. In particular, our approach accepts more type-correct programs than previous approaches when they do not employ type annotations. A side benefit of our approach is that it can detect a wide range of runtime errors that are missed by previous approaches. Our method is based on the idea to represent type refinements in pattern-matching branches by choice types, which facilitate a separation of the typing and reconciliation phases and thus support case expressions. This idea is formalized in a type system, which is both sound and a conservative extension of the classical Hindley-Milner system. We present the results of an empirical evaluation that compares our algorithm with previous approaches.

References

  1. M. Blume, U. A. Acar, and W. Chae. Extensible programming with first-class cases. In ACM SIGPLAN International Conference on Functional Programming, pages 239–250, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. S. Chen and M. Erwig. Counter-factual typing for debugging type errors. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 583–594, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. S. Chen and M. Erwig. Guided type debugging. In Functional and Logic Programming, LNCS 8475, pages 35–51. 2014.Google ScholarGoogle Scholar
  4. S. Chen, M. Erwig, and E. Walkingshaw. An error-tolerant type system for variational lambda calculus. In ACM SIGPLAN International Conference on Functional Programming, pages 29–40, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. S. Chen, M. Erwig, and E. Walkingshaw. Extending type inference to variational programs. ACM Trans. Program. Lang. Syst., 36(1):1:1– 1:54, Mar. 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. J. Cheney and R. Hinze. A lightweight implementation of generics and dynamics. In ACM SIGPLAN Workshop on Haskell, pages 90– 104, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. L. Damas and R. Milner. Principal Type-Schemes for Functional Programs. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 207–212, 1982. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. M. Felleisen, R. B. Findler, M. Flatt, and S. Krishnamurthi. How to design programs. MIT Press Cambridge, 2001.Google ScholarGoogle Scholar
  9. J. Garrigue and J. L. Normand. Adding gadts to ocaml: the direct approach. In Workshop on ML, 2011.Google ScholarGoogle Scholar
  10. J. Garrigue and D. Rémy. Ambivalent types for principal type inference with GADTs. In Programming Languages and Systems, LNCS 8301, pages 257–272. 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. F. Henglein. Type inference with polymorphic recursion. ACM Trans. Program. Lang. Syst., 15(2):253–289, Apr. 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. G. Karachalias, T. Schrijvers, D. Vytiniotis, and S. P. Jones. Gadts meet their match: Pattern-matching warnings that account for gadts, guards, and laziness. In ACM SIGPLAN International Conference on Functional Programming, pages 424–436, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. C. Kästner, P. G. Giarrusso, T. Rendel, S. Erdweg, K. Ostermann, and T. Berger. Variability-Aware Parsing in the Presence of Lexical Macros and Conditional Compilation. In ACM SIGPLAN Int. Conf. on Object-Oriented Programming, Systems, Languages, and Applications, pages 805–824, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. A. J. Kfoury, J. Tiuryn, and P. Urzyczyn. Type reconstruction in the presence of polymorphic recursion. ACM Trans. Program. Lang. Syst., 15(2):290–311, Apr. 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. J. Liebig, A. von Rhein, C. Kästner, S. Apel, J. Dörre, and C. Lengauer. Scalable analysis of variable software. In Foundations of Software Engineering, pages 81–91, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. C.-k. Lin. Programming monads operationally with unimo. In ACM SIGPLAN International Conference on Functional Programming, pages 274–285, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. C.-k. Lin. Practical Type Inference for the GADT Type System. PhD thesis, Portland State University, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. C.-k. Lin and T. Sheard. Pointwise generalized algebraic data types. In ACM SIGPLAN Workshop on Types in Language Design and Implementation, pages 51–62, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. A. Mycroft. Polymorphic type schemes and recursive definitions. In International Symposium on Programming, LNCS 167, pages 217– 228, 1984. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. M. Odersky, M. Sulzmann, and M. Wehr. Type Inference with Constrained Types. Theory and Practice of Object Systems, 5(1):35–55, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. S. Peyton Jones, D. Vytiniotis, S. Weirich, and G. Washburn. Simple unification-based type inference for GADTs. In ACM SIGPLAN International Conference on Functional Programming, pages 50–61, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. S. Peyton Jones, G. Washburn, and S. Weirich. Wobbly types: type inference for generalised algebraic data types. Technical Report MSCIS-05-26, University of Pennsylvania, July 2004.Google ScholarGoogle Scholar
  23. B. C. Pierce. Programming with intersection types, union types, and polymorphism. Technical Report CMU-CS-91-106, School of Computer Science, Carnegie Mellon University, 1991.Google ScholarGoogle Scholar
  24. B. C. Pierce. Types and Programming Languages. MIT Press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. F. Pottier and Y. Régis-Gianas. Stratified type inference for generalized algebraic data types. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 232–244, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. N. Ramsey. On teaching *how to design programs*: Observations from a newcomer. In ACM SIGPLAN International Conference on Functional Programming, pages 153–166, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. T. Schrijvers, S. Peyton Jones, M. Sulzmann, and D. Vytiniotis. Complete and decidable type inference for GADTs. In ACM SIGPLAN International Conference on Functional Programming, pages 341–352, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. T. Sheard. Generic programming in Omega. In Datatype-Generic Programming, LNCS 4719, pages 258–284, 2006.Google ScholarGoogle Scholar
  29. T. Sheard and N. Linger. Programming in Omega. In CEFP, LNCS 5161, pages 158–227, 2007.Google ScholarGoogle Scholar
  30. V. Simonet and F. Pottier. A constraint-based approach to guarded algebraic data types. ACM Trans. on Programming Languages and Systems, 29(1):1–38, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. P. J. Stuckey and M. Sulzmann. Type inference for guarded recursive data types. CoRR, abs/cs/0507037:1–15, 2005.Google ScholarGoogle Scholar
  32. M. Sulzmann, T. Schrijvers, and P. J. Stuckey. Type inference for GADTs via Herbrand constraint abduction. Technical Report CW507, University of Leuven, January 2008.Google ScholarGoogle Scholar
  33. S. Vorobyov. An improved lower bound for the elementary theories of trees. In International Conference on Automated Deduction, LNCS 1104, pages 275–287. 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. D. Vytiniotis, S. Peyton Jones, T. Schrijvers, and M. Sulzmann. Outsidein(x) modular type inference with local assumptions. Journal of Functional Programming, 21(4-5):333–412, Sept. 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. S. Weirich. Depending on types. In ACM SIGPLAN International Conference on Functional Programming, pages 241–241, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. H. Xi, C. Chen, and G. Chen. Guarded recursive datatype constructors. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 224–235, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Principal type inference for GADTs

        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 1
          POPL '16
          January 2016
          815 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2914770
          • Editor:
          • Andy Gill
          Issue’s Table of Contents
          • cover image ACM Conferences
            POPL '16: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages
            January 2016
            815 pages
            ISBN:9781450335492
            DOI:10.1145/2837614

          Copyright © 2016 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 11 January 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!