Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article

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

Published: 29 August 2015 Publication History

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.
[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.
[3]
E. Brady. Idris, a general-purpose dependently typed programming language: Design and implementation. Journal of Functional Programming, 23:552–593, 9 2013.
[4]
J. Cheney and R. Hinze. First-class phantom types. Technical report, Cornell University, 2003.
[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.
[6]
T. Coquand. Pattern matching with dependent types. In Proceedings of the Workshop on Types for Proofs and Programs, 1992.
[7]
J. Dunfield. A Unified System of Type Refinements. PhD thesis, Carnegie Mellon University, Aug. 2007. CMU-CS-07-129.
[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.
[10]
M. Erwig and S. Peyton Jones. Pattern guards and transformational patterns. In Proceedings of the 2000 Haskell Symposium. ACM, 2000.
[11]
J. Garrigue and J. L. Normand. Adding GADTs to OCaml: the direct approach. In Workshop on ML, 2011.
[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.
[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.
[14]
A. Laville. Comparison of priority rules in pattern matching and term rewriting. J. Symb. Comput., 11(4):321–347, May 1991.
[15]
F. Le Fessant and L. Maranget. Optimizing pattern-matching. In Proceedings of the 2001 International Conference on Functional Programming, 2001.
[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.
[17]
L. Maranget. Warnings for pattern matching. Journal of Functional Programming, 17:387–421, 2007.
[18]
L. Maranget. Compiling pattern matching to good decision trees. In Proceedings of the ACM Workshop on ML, 2008.
[19]
L. Maranget and P. Para. Two techniques for compiling lazy pattern matching. Technical report, 1994.
[20]
The Coq development team. The Coq proof assistant reference manual. LogiCal Project, 2004. URL http://coq.inria.fr. Version 8.0.
[21]
C. McBride and J. McKinna. The view from the left. Journal of Functional Programming, 14(1):69–111, 2004.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[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.
[38]
H. Xi. Dependent Types in Practical Programming. PhD thesis, Carnegie Mellon University, Sept. 1998.
[39]
H. Xi. Dependently typed pattern matching. Journal of Universal Computer Science, 9:851–872, 2003.
[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.
[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.
[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.
[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.

Cited By

View all
  • (2019)Overview of generalized algebraic data types in OCaml2019 5TH INTERNATIONAL CONFERENCE ON GREEN POWER, MATERIALS AND MANUFACTURING TECHNOLOGY AND APPLICATIONS (GPMMTA 2019)10.1063/1.5137873(020029)Online publication date: 2019
  • (2023)Bit-Stealing Made Legal: Compilation for Custom Memory Representations of Algebraic Data TypesProceedings of the ACM on Programming Languages10.1145/36078587:ICFP(813-846)Online publication date: 31-Aug-2023
  • (2023)Live Pattern Matching with Typed HolesProceedings of the ACM on Programming Languages10.1145/35860487:OOPSLA1(609-635)Online publication date: 6-Apr-2023
  • Show More Cited By

Index Terms

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

      Recommendations

      Comments

      Information & Contributors

      Information

      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
      Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      Published: 29 August 2015
      Published in SIGPLAN Volume 50, Issue 9

      Check for updates

      Author Tags

      1. Generalized Algebraic Data Types
      2. Haskell
      3. OutsideIn(X)
      4. pattern matching

      Qualifiers

      • Research-article

      Contributors

      Other Metrics

      Bibliometrics & Citations

      Bibliometrics

      Article Metrics

      • Downloads (Last 12 months)13
      • Downloads (Last 6 weeks)0
      Reflects downloads up to 27 Jan 2025

      Other Metrics

      Citations

      Cited By

      View all
      • (2019)Overview of generalized algebraic data types in OCaml2019 5TH INTERNATIONAL CONFERENCE ON GREEN POWER, MATERIALS AND MANUFACTURING TECHNOLOGY AND APPLICATIONS (GPMMTA 2019)10.1063/1.5137873(020029)Online publication date: 2019
      • (2023)Bit-Stealing Made Legal: Compilation for Custom Memory Representations of Algebraic Data TypesProceedings of the ACM on Programming Languages10.1145/36078587:ICFP(813-846)Online publication date: 31-Aug-2023
      • (2023)Live Pattern Matching with Typed HolesProceedings of the ACM on Programming Languages10.1145/35860487:OOPSLA1(609-635)Online publication date: 6-Apr-2023
      • (2022)A case for DOT: theoretical foundations for objects with pattern matching and GADT-style reasoningProceedings of the ACM on Programming Languages10.1145/35633426:OOPSLA2(1526-1555)Online publication date: 31-Oct-2022
      • (2020)Eliminating bugs with dependent Haskell (experience report)Proceedings of the 13th ACM SIGPLAN International Symposium on Haskell10.1145/3406088.3409020(9-16)Online publication date: 27-Aug-2020
      • (2019)Constraint-based type-directed program synthesisProceedings of the 4th ACM SIGPLAN International Workshop on Type-Driven Development10.1145/3331554.3342608(64-76)Online publication date: 18-Aug-2019
      • (2019)Sound and complete bidirectional typechecking for higher-rank polymorphism with existentials and indexed typesProceedings of the ACM on Programming Languages10.1145/32903223:POPL(1-28)Online publication date: 2-Jan-2019
      • (2017)GADTs and Exhaustiveness: Looking for the ImpossibleElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.241.2241(23-35)Online publication date: 7-Feb-2017
      • (2016)Principal type inference for GADTsACM SIGPLAN Notices10.1145/2914770.283766551:1(416-428)Online publication date: 11-Jan-2016
      • (2016)Principal type inference for GADTsProceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages10.1145/2837614.2837665(416-428)Online publication date: 11-Jan-2016

      View Options

      Login options

      View options

      PDF

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader

      Figures

      Tables

      Media

      Share

      Share

      Share this Publication link

      Share on social media