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

Live Pattern Matching with Typed Holes

Published: 06 April 2023 Publication History

Abstract

Several modern programming systems, including GHC Haskell, Agda, Idris, and Hazel, support typed holes. Assigning static and, to varying degree, dynamic meaning to programs with holes allows program editors and other tools to offer meaningful feedback and assistance throughout editing, i.e. in a live manner. Prior work, however, has considered only holes appearing in expressions and types. This paper considers, from type theoretic and logical first principles, the problem of typed pattern holes. We confront two main difficulties, (1) statically reasoning about exhaustiveness and irredundancy when patterns are not fully known, and (2) live evaluation of expressions containing both pattern and expression holes. In both cases, this requires reasoning conservatively about all possible hole fillings. We develop a typed lambda calculus, Peanut, where reasoning about exhaustiveness and redundancy is mapped to the problem of deriving first order entailments. We equip Peanut with an operational semantics in the style of Hazelnut Live that allows us to evaluate around holes in both expressions and patterns. We mechanize the metatheory of Peanut in Agda and formalize a procedure capable of deciding the necessary entailments. Finally, we scale up and implement these mechanisms within Hazel, a programming environment for a dialect of Elm that automatically inserts holes during editing to provide static and dynamic feedback to the programmer in a maximally live manner, i.e. for every possible editor state. Hazel is the first maximally live environment for a general-purpose functional language.

References

[1]
Andreas Abel, Brigitte Pientka, David Thibodeau, and Anton Setzer. 2013. Copatterns: programming infinite structures by observations. In The 40th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’13, Rome, Italy - January 23 - 25, 2013, Roberto Giacobazzi and Radhia Cousot (Eds.). ACM, 27–38. https://doi.org/10.1145/2429069.2429075
[2]
William Aitken. 1992. SML/NJ Match Compiler Notes. https://www.smlnj.org/compiler-notes/matchcomp.ps
[3]
Lennart Augustsson. 1984. A Compiler for Lazy ML. In Proceedings of the 1984 ACM Conference on LISP and Functional Programming, LFP 1984, Austin, Texas, USA, August 5-8, 1984, Robert S. Boyer, Edward S. Schneider, and Guy L. Steele Jr. (Eds.). ACM, 218–227. https://doi.org/10.1145/800055.802038
[4]
Lennart Augustsson. 1985. Compiling Pattern Matching. In Functional Programming Languages and Computer Architecture, FPCA 1985, Nancy, France, September 16-19, 1985, Proceedings, Jean-Pierre Jouannaud (Ed.) (Lecture Notes in Computer Science, Vol. 201). Springer, 368–381. https://doi.org/10.1007/3-540-15975-4_48
[5]
Steven Awodey, Nicola Gambino, and Kristina Sojakova. 2012. Inductive Types in Homotopy Type Theory. In Proceedings of the 27th Annual IEEE Symposium on Logic in Computer Science, LICS 2012, Dubrovnik, Croatia, June 25-28, 2012. IEEE Computer Society, 95–104. https://doi.org/10.1109/LICS.2012.21
[6]
Hendrik Pieter Barendregt. 1985. The lambda calculus - its syntax and semantics (Studies in logic and the foundations of mathematics, Vol. 103). North-Holland. isbn:978-0-444-86748-3
[7]
Marianne Baudinet and David MacQueen. 1985. Tree Pattern Matching for ML (Extended Abstract). https://smlfamily.github.io/history/Baudinet-DM-tree-pat-match-12-85.pdf
[8]
Frédéric Bour, Thomas Refis, and Gabriel Scherer. 2018. Merlin: a language server for OCaml (experience report). Proc. ACM Program. Lang., 2, ICFP (2018), 103:1–103:15. https://doi.org/10.1145/3236798
[9]
Edwin Brady. 2013. Idris, A General-Purpose Dependently Typed Programming Language: Design and Implementation. Journal of Functional Programming, 23, 05 (2013), 552–593. https://doi.org/10.1017/S095679681300018X
[10]
Rod M. Burstall. 1969. Proving Properties of Programs by Structural Induction. Comput. J., 12, 1 (1969), 41–48. https://doi.org/10.1093/comjnl/12.1.41
[11]
Rod M. Burstall, David B. MacQueen, and Donald Sannella. 1980. HOPE: An Experimental Applicative Language. In Proceedings of the 1980 LISP Conference, Stanford, California, USA, August 25-27, 1980. ACM, 136–143. https://doi.org/10.1145/800087.802799
[12]
Luca Cardelli. 1984. Compiling a Functional Language. In Proceedings of the 1984 ACM Conference on LISP and Functional Programming, LFP 1984, Austin, Texas, USA, August 5-8, 1984, Robert S. Boyer, Edward S. Schneider, and Guy L. Steele Jr. (Eds.). ACM, 208–217. https://doi.org/10.1145/800055.802037
[13]
Jesper Cockx and Andreas Abel. 2018. Elaborating dependent (co)pattern matching. Proc. ACM Program. Lang., 2, ICFP (2018), 75:1–75:30. https://doi.org/10.1145/3236770
[14]
Lukas Convent, Sam Lindley, Conor McBride, and Craig McLaughlin. 2020. Doo bee doo bee doo. J. Funct. Program., 30 (2020), e9. https://doi.org/10.1017/S0956796820000039
[15]
Jana Dunfield and Neel Krishnaswami. 2021. Bidirectional Typing. ACM Comput. Surv., 54, 5 (2021), 98:1–98:38. https://doi.org/10.1145/3450952
[16]
Joseph Eremondi, Ronald Garcia, and Éric Tanter. 2022. Propositional equality for gradual dependently typed programming. Proc. ACM Program. Lang., 6, ICFP (2022), 165–193. https://doi.org/10.1145/3547627
[17]
Joseph Eremondi, Éric Tanter, and Ronald Garcia. 2019. Approximate normalization for gradual dependent types. Proc. ACM Program. Lang., 3, ICFP (2019), 88:1–88:30. https://doi.org/10.1145/3341692
[18]
Matthías Páll Gissurarson. 2018. Suggesting valid hole fits for typed-holes (experience report). In Proceedings of the 11th ACM SIGPLAN International Symposium on Haskell, Haskell@ICFP 2018, St. Louis, MO, USA, September 27-17, 2018, Nicolas Wu (Ed.). ACM, 179–185. https://doi.org/10.1145/3242744.3242760
[19]
Sebastian Graf, Simon Peyton Jones, and Ryan G. Scott. 2020. Lower your guards: a compositional pattern-match coverage checker. Proc. ACM Program. Lang., 4, ICFP (2020), 107:1–107:30. https://doi.org/10.1145/3408989
[20]
Robert Harper. 2012. Practical Foundations for Programming Languages. Cambridge University Press. https://doi.org/10.1017/CBO9781139342131
[21]
Georgios Karachalias, Tom Schrijvers, Dimitrios Vytiniotis, and Simon L. Peyton Jones. 2015. GADTs meet their match: pattern-matching warnings that account for GADTs, guards, and laziness. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming, ICFP 2015, Vancouver, BC, Canada, September 1-3, 2015, Kathleen Fisher and John H. Reppy (Eds.). ACM, 424–436. https://doi.org/10.1145/2784731.2784748
[22]
Lennart C. L. Kats, Maartje de Jonge, Emma Nilsson-Nyman, and Eelco Visser. 2009. Providing rapid feedback in generated modular language environments: adding error recovery to scannerless generalized-LR parsing. In Proceedings of the 24th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications, OOPSLA 2009, October 25-29, 2009, Orlando, Florida, USA, Shail Arora and Gary T. Leavens (Eds.). ACM, 445–464. https://doi.org/10.1145/1640089.1640122
[23]
Neelakantan R. Krishnaswami. 2009. Focusing on pattern matching. In Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2009, Savannah, GA, USA, January 21-23, 2009, Zhong Shao and Benjamin C. Pierce (Eds.). ACM, 366–378. https://doi.org/10.1145/1480881.1480927
[24]
Meven Lennon-Bertrand, Kenji Maillard, Nicolas Tabareau, and Éric Tanter. 2022. Gradualizing the Calculus of Inductive Constructions. ACM Trans. Program. Lang. Syst., 44, 2 (2022), 7:1–7:82. https://doi.org/10.1145/3495528
[25]
Justin Lubin, Nick Collins, Cyrus Omar, and Ravi Chugh. 2020. Program sketching with live bidirectional evaluation. Proc. ACM Program. Lang., 4, ICFP (2020), 109:1–109:29. https://doi.org/10.1145/3408991
[26]
Kenji Maillard, Meven Lennon-Bertrand, Nicolas Tabareau, and Éric Tanter. 2022. A reasonably gradual type theory. Proc. ACM Program. Lang., 6, ICFP (2022), 931–959. https://doi.org/10.1145/3547655
[27]
Stefan Malewski, Michael Greenberg, and Éric Tanter. 2021. Gradually structured data. Proc. ACM Program. Lang., 5, OOPSLA (2021), 1–29. https://doi.org/10.1145/3485503
[28]
Luc Maranget. 1994. Two Techniques for Compiling Lazy Pattern Matching. HAL-Inria. https://hal.inria.fr/inria-00074292/document
[29]
Luc Maranget. 2007. Warnings for pattern matching. J. Funct. Program., 17, 3 (2007), 387–421. https://doi.org/10.1017/S0956796807006223
[30]
Frederick Valentine McBride. 1970. Computer aided manipulation of symbols. Ph. D. Dissertation. Queen’s University Belfast, UK. https://ethos.bl.uk/OrderDetails.do?uin=uk.bl.ethos.463849
[31]
Robin Milner. 1978. A Theory of Type Polymorphism in Programming. J. Comput. Syst. Sci., 17, 3 (1978), 348–375. https://doi.org/10.1016/0022-0000(78)90014-4
[32]
Aleksandar Nanevski, Frank Pfenning, and Brigitte Pientka. 2008. Contextual modal type theory. ACM Trans. Comput. Log., 9, 3 (2008), 23:1–23:49. https://doi.org/10.1145/1352582.1352591
[33]
Ulf Norell. 2007. Towards a practical programming language based on dependent type theory. Ph. D. Dissertation. Department of Computer Science and Engineering, Chalmers University of Technology. SE-412 96 Göteborg, Sweden. https://www.cse.chalmers.se/~ulfn/papers/thesis.pdf
[34]
Cyrus Omar, Ian Voysey, Ravi Chugh, and Matthew A. Hammer. 2019. Live functional programming with typed holes. Proc. ACM Program. Lang., 3, POPL (2019), 14:1–14:32. https://doi.org/10.1145/3290327
[35]
Cyrus Omar, Ian Voysey, Michael Hilton, Jonathan Aldrich, and Matthew A. Hammer. 2017. Hazelnut: a bidirectionally typed structure editor calculus. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, Paris, France, January 18-20, 2017, Giuseppe Castagna and Andrew D. Gordon (Eds.). ACM, 86–99. http://dl.acm.org/citation.cfm?id=3009900
[36]
Cyrus Omar, Ian Voysey, Michael Hilton, Joshua Sunshine, Claire Le Goues, Jonathan Aldrich, and Matthew A. Hammer. 2017. Toward Semantic Foundations for Program Editors. In Summit on Advances in Programming Languages (SNAPL). https://doi.org/10.4230/LIPIcs.SNAPL.2017.11
[37]
Simon Peyton Jones, Sean Leather, and Thijs Alkemade. 2020. Glasgow Haskell Compiler 9.2.1 User’s Guide (Typed Holes). https://downloads.haskell.org/ ghc/latest/docs/html/users_guide/exts/typed_holes.html
[38]
Brigitte Pientka and Jana Dunfield. 2008. Programming with proofs and explicit contexts. In Proceedings of the 10th International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming, July 15-17, 2008, Valencia, Spain, Sergio Antoy and Elvira Albert (Eds.). ACM, 163–173. https://doi.org/10.1145/1389449.1389469
[39]
Gordon D. Plotkin. 2004. A structural approach to operational semantics. J. Log. Algebraic Methods Program., 60-61 (2004), 17–139.
[40]
Hannah Potter and Cyrus Omar. 2020. Hazel Tutor: Guiding Novices Through Type-Driven Development Strategies. https://hazel.org/hazeltutor-hatra2020.pdf
[41]
John Reppy and Mona Zahir. 2019. Compiling Successor ML Pattern Guards. https://github.com/JohnReppy/compiling-pattern-guards/blob/master/ml19-paper.pdf
[42]
Peter Sestoft. 1996. ML pattern match compilation and partial evaluation. In Partial Evaluation, Olivier Danvy, Robert Glück, and Peter Thiemann (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 446–464. isbn:978-3-540-70589-5
[43]
Jeremy Siek and Walid Taha. 2006. Gradual typing for functional languages. Scheme and Functional Programming, http://scheme2006.cs.uchicago.edu/13-siek.pdf
[44]
Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, and John Tang Boyland. 2015. Refined Criteria for Gradual Typing. In 1st Summit on Advances in Programming Languages, SNAPL 2015, May 3-6, 2015, Asilomar, California, USA, Thomas Ball, Rastislav Bodík, Shriram Krishnamurthi, Benjamin S. Lerner, and Greg Morrisett (Eds.) (LIPIcs, Vol. 32). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 274–293. https://doi.org/10.4230/LIPIcs.SNAPL.2015.274
[45]
Matthieu Sozeau. 2010. Equations: A Dependent Pattern-Matching Compiler. In Interactive Theorem Proving, First International Conference, ITP 2010, Edinburgh, UK, July 11-14, 2010. Proceedings, Matt Kaufmann and Lawrence C. Paulson (Eds.) (Lecture Notes in Computer Science, Vol. 6172). Springer, 419–434. https://doi.org/10.1007/978-3-642-14052-5_29
[46]
Steven L. Tanimoto. 2013. A perspective on the evolution of live programming. In 2013 1st International Workshop on Live Programming (LIVE). 31–34. https://doi.org/10.1109/LIVE.2013.6617346
[47]
D. A. Turner. 1979. A New Implementation Technique for Applicative Languages. Softw. Pract. Exp., 9, 1 (1979), 31–49. https://doi.org/10.1002/spe.4380090105
[48]
Christian Urban, Stefan Berghofer, and Michael Norrish. 2007. Barendregt’s Variable Convention in Rule Inductions. In Automated Deduction - CADE-21, 21st International Conference on Automated Deduction, Bremen, Germany, July 17-20, 2007, Proceedings, Frank Pfenning (Ed.) (Lecture Notes in Computer Science, Vol. 4603). Springer, 35–50. https://doi.org/10.1007/978-3-540-73595-3_4
[49]
Niki Vazou, Eric L. Seidel, Ranjit Jhala, Dimitrios Vytiniotis, and Simon L. Peyton Jones. 2014. Refinement types for Haskell. In Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming, Gothenburg, Sweden, September 1-3, 2014, Johan Jeuring and Manuel M. T. Chakravarty (Eds.). ACM, 269–282. https://doi.org/10.1145/2628136.2628161
[50]
Dimitrios Vytiniotis, Simon L. Peyton Jones, and José Pedro Magalhães. 2012. Equality proofs and deferred type errors: a compiler pearl. In ACM SIGPLAN International Conference on Functional Programming, ICFP’12, Copenhagen, Denmark, September 9-15, 2012, Peter Thiemann and Robby Bruce Findler (Eds.). ACM, 341–352. https://doi.org/10.1145/2364527.2364554
[51]
Yongwei Yuan, Scott Guest, Eric Griffis, Hannah Potter, David Moon, and Cyrus Omar. 2023. Artifact for "Live Pattern Matching with Typed Holes". https://doi.org/10.5281/zenodo.7713722

Cited By

View all
  • (2024)Haskelite: A Tracing Interpreter Based on a Pattern-Matching CalculusProceedings of the 17th ACM SIGPLAN International Haskell Symposium10.1145/3677999.3678274(1-13)Online publication date: 29-Aug-2024
  • (2024)Total Type Error Localization and Recovery with HolesProceedings of the ACM on Programming Languages10.1145/36329108:POPL(2041-2068)Online publication date: 5-Jan-2024

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 7, Issue OOPSLA1
April 2023
901 pages
EISSN:2475-1421
DOI:10.1145/3554309
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution 4.0 International License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 06 April 2023
Published in PACMPL Volume 7, Issue OOPSLA1

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. pattern matching
  2. typed holes

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)389
  • Downloads (Last 6 weeks)42
Reflects downloads up to 01 Sep 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Haskelite: A Tracing Interpreter Based on a Pattern-Matching CalculusProceedings of the 17th ACM SIGPLAN International Haskell Symposium10.1145/3677999.3678274(1-13)Online publication date: 29-Aug-2024
  • (2024)Total Type Error Localization and Recovery with HolesProceedings of the ACM on Programming Languages10.1145/36329108:POPL(2041-2068)Online publication date: 5-Jan-2024

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media