skip to main content
research-article

GADTs meet their match: pattern-matching warnings that account for GADTs, guards, and laziness

Published:29 August 2015Publication History
Skip Abstract Section

Abstract

For ML and Haskell, accurate warnings when a function definition has redundant or missing patterns are mission critical. But today's compilers generate bogus warnings when the programmer uses guards (even simple ones), GADTs, pattern guards, or view patterns. We give the first algorithm that handles all these cases in a single, uniform framework, together with an implementation in GHC, and evidence of its utility in practice.

References

  1. L. Augustsson. Compiling pattern matching. In Proceedings of the 1985 Conference on Functional Programming and Computer Architecture, 1985. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. E. Brady. Programming and reasoning with algebraic effects and dependent types. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP ’13, pages 133– 144, New York, NY, USA, 2013. ACM.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. E. Brady. Idris, a general-purpose dependently typed programming language: Design and implementation. Journal of Functional Programming, 23:552–593, 9 2013..Google ScholarGoogle ScholarCross RefCross Ref
  4. J. Cheney and R. Hinze. First-class phantom types. Technical report, Cornell University, 2003.Google ScholarGoogle Scholar
  5. K. Claessen, M. Johansson, D. Rosén, and N. Smallbone. Automating inductive proofs using theory exploration. In M. P. Bonacina, editor, CADE, volume 7898 of Lecture Notes in Computer Science, pages 392–406. Springer, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. T. Coquand. Pattern matching with dependent types. In Proceedings of the Workshop on Types for Proofs and Programs, 1992.Google ScholarGoogle Scholar
  7. J. Dunfield. A Unified System of Type Refinements. PhD thesis, Carnegie Mellon University, Aug. 2007. CMU-CS-07-129.Google ScholarGoogle Scholar
  8. J. Dunfield. Refined typechecking with Stardust. In Proceedings of the 2007 Workshop on Programming Languages Meets Program Verification, PLPV ’07, pages 21–32, New York, NY, USA, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. ACM..Google ScholarGoogle Scholar
  10. M. Erwig and S. Peyton Jones. Pattern guards and transformational patterns. In Proceedings of the 2000 Haskell Symposium. ACM, 2000.Google ScholarGoogle Scholar
  11. J. Garrigue and J. L. Normand. Adding GADTs to OCaml: the direct approach. In Workshop on ML, 2011.Google ScholarGoogle Scholar
  12. G. Karachalias, T. Schrijvers, D. Vytiniotis, and S. P. Jones. GADTs meet their match (extended version). Technical report, KU Leuven, 2015. URL http://people.cs.kuleuven.be/~george. karachalias/papers/gadtpm_ext.pdf.Google ScholarGoogle Scholar
  13. N. R. Krishnaswami. Focusing on pattern matching. In Proceedings of the 36th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’09, pages 366–378, New York, NY, USA, 2009. ACM.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. A. Laville. Comparison of priority rules in pattern matching and term rewriting. J. Symb. Comput., 11(4):321–347, May 1991.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. F. Le Fessant and L. Maranget. Optimizing pattern-matching. In Proceedings of the 2001 International Conference on Functional Programming, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. L. Maranget. Compiling lazy pattern matching. In Proceedings of the 1992 ACM Conference on LISP and Functional Programming, LFP ’92, pages 21–31, New York, NY, USA, 1992. ACM.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. L. Maranget. Warnings for pattern matching. Journal of Functional Programming, 17:387–421, 2007.Google ScholarGoogle ScholarCross RefCross Ref
  18. L. Maranget. Compiling pattern matching to good decision trees. In Proceedings of the ACM Workshop on ML, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. L. Maranget and P. Para. Two techniques for compiling lazy pattern matching. Technical report, 1994.Google ScholarGoogle Scholar
  20. The Coq development team. The Coq proof assistant reference manual. LogiCal Project, 2004. URL http://coq.inria.fr. Version 8.0.Google ScholarGoogle Scholar
  21. C. McBride and J. McKinna. The view from the left. Journal of Functional Programming, 14(1):69–111, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. N. Mitchell and C. Runciman. Not all patterns, but enough: An automatic verifier for partial but sufficient pattern matching. In Proceedings of the First ACM SIGPLAN Symposium on Haskell, Haskell ’08, pages 49–60, New York, NY, USA, 2008. ACM.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. U. Norell. Towards a practical programming language based on dependent type theory. PhD thesis, Department of Computer Science and Engineering, Chalmers University of Technology, SE-412 96 Göteborg, Sweden, September 2007.Google ScholarGoogle Scholar
  24. S. Peyton Jones, D. Vytiniotis, S. Weirich, and G. Washburn. Simple unification-based type inference for GADTs. In Proceedings of the Eleventh ACM SIGPLAN International Conference on Functional Programming, ICFP ’06, pages 50–61, New York, NY, USA, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. ACM..Google ScholarGoogle Scholar
  26. P. M. Rondon, M. Kawaguci, and R. Jhala. Liquid types. In Proceedings of the 2008 ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’08, pages 159–169, New York, NY, USA, 2008. ACM.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. T. Schrijvers, S. Peyton Jones, M. Sulzmann, and D. Vytiniotis. Complete and decidable type inference for GADTs. In Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming, ICFP ’09, pages 341–352, New York, NY, USA, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. ACM..Google ScholarGoogle Scholar
  29. R. C. Sekar, R. Ramesh, and I. V. Ramakrishnan. Adaptive pattern matching. SIAM J. Comput., 24(6):1207–1234, Dec. 1995. ISSN 0097-5397.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. P. Sestoft. ML pattern match compilation and partial evaluation. In O. Danvy, R. Glück, and P. Thiemann, editors, Partial Evaluation, volume 1110 of Lecture Notes in Computer Science, pages 446–464. Springer Berlin Heidelberg, 1996.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. T. Sheard. Languages of the future. In In OOPSLA ’04: Companion to the 19th annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications, pages 116–119. ACM Press, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. W. Sonnex, S. Drossopoulou, and S. Eisenbach. Zeno: An automated prover for properties of recursive data structures. pages 407–421. Springer-Verlag Berlin, 2012.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. P. Thiemann. Avoiding repeated tests in pattern matching. In G. Filé, editor, 3rd International Workshop on Static Analysis, number 724, pages 141–152, Padova, Italia, Sept. 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. N. Vazou, E. L. Seidel, R. Jhala, D. Vytiniotis, and S. Peyton-Jones. Refinement types for Haskell. In Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming, ICFP ’14, pages 269–282, New York, NY, USA, 2014. ACM.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. P. Wadler. Views: A way for pattern matching to cohabit with data abstraction. In Proceedings of the 14th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, POPL ’87, pages 307–313, New York, NY, USA, 1987. ACM.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. P. Wadler. Efficient compilation of pattern matching. In S. Peyton Jones, editor, The implementation of functional programming languages, pages 78–103. Prentice Hall, 1987.Google ScholarGoogle Scholar
  37. H. Xi. Dead code elimination through dependent types. In Proceedings of the First International Workshop on Practical Aspects of Declarative Languages, PADL ’99, pages 228–242, London, UK, 1998. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. H. Xi. Dependent Types in Practical Programming. PhD thesis, Carnegie Mellon University, Sept. 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. H. Xi. Dependently typed pattern matching. Journal of Universal Computer Science, 9:851–872, 2003.Google ScholarGoogle Scholar
  40. H. Xi, C. Chen, and G. Chen. Guarded recursive datatype constructors. In Proceedings of the 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’03, pages 224–235, New York, NY, USA, 2003. ACM.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. D. N. Xu. Extended static checking for Haskell. In Proceedings of the 2006 ACM SIGPLAN Workshop on Haskell, Haskell ’06, pages 48–59, New York, NY, USA, 2006. ACM.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. D. N. Xu, S. Peyton Jones, and K. Claessen. Static contract checking for Haskell. In Proceedings of the 36th Annual ACM SIGPLANSIGACT Symposium on Principles of Programming Languages, POPL ’09, pages 41–52, New York, NY, USA, 2009. ACM.. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. B. A. Yorgey, S. Weirich, J. Cretin, S. Peyton Jones, D. Vytiniotis, and J. P. Magalhães. Giving Haskell a promotion. In Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation, TLDI ’12, pages 53–66, New York, NY, USA, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. GADTs meet their match: pattern-matching warnings that account for GADTs, guards, and laziness

      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 50, Issue 9
        ICFP '15
        September 2015
        436 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/2858949
        • Editor:
        • Andy Gill
        Issue’s Table of Contents
        • cover image ACM Conferences
          ICFP 2015: Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming
          August 2015
          436 pages
          ISBN:9781450336697
          DOI:10.1145/2784731

        Copyright © 2015 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 29 August 2015

        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!