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.
- 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
Google Scholar
Digital Library
- William Aitken. 1992. SML/NJ Match Compiler Notes. https://www.smlnj.org/compiler-notes/matchcomp.ps
Google Scholar
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Cross Ref
- 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
Google Scholar
Digital Library
- 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
Google Scholar
- 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
Google Scholar
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Cross Ref
- 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
Google Scholar
Cross Ref
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Cross Ref
- Jana Dunfield and Neel Krishnaswami. 2021. Bidirectional Typing. ACM Comput. Surv., 54, 5 (2021), 98:1–98:38. https://doi.org/10.1145/3450952
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- 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, [email protected] 2018, St. Louis, MO, USA, September 27-17, 2018, Nicolas Wu (Ed.). ACM, 179–185. https://doi.org/10.1145/3242744.3242760
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- Robert Harper. 2012. Practical Foundations for Programming Languages. Cambridge University Press. https://doi.org/10.1017/CBO9781139342131
Google Scholar
Cross Ref
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- Luc Maranget. 1994. Two Techniques for Compiling Lazy Pattern Matching. HAL-Inria. https://hal.inria.fr/inria-00074292/document
Google Scholar
- Luc Maranget. 2007. Warnings for pattern matching. J. Funct. Program., 17, 3 (2007), 387–421. https://doi.org/10.1017/S0956796807006223
Google Scholar
Cross Ref
- 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
Google Scholar
- 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
Google Scholar
Cross Ref
- 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
Google Scholar
Digital Library
- 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
Google Scholar
- 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
Google Scholar
Digital Library
- 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
Google Scholar
- 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
Google Scholar
Cross Ref
- 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
Google Scholar
- 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
Google Scholar
Digital Library
- Gordon D. Plotkin. 2004. A structural approach to operational semantics. J. Log. Algebraic Methods Program., 60-61 (2004), 17–139.
Google Scholar
- Hannah Potter and Cyrus Omar. 2020. Hazel Tutor: Guiding Novices Through Type-Driven Development Strategies. https://hazel.org/hazeltutor-hatra2020.pdf
Google Scholar
- John Reppy and Mona Zahir. 2019. Compiling Successor ML Pattern Guards. https://github.com/JohnReppy/compiling-pattern-guards/blob/master/ml19-paper.pdf
Google Scholar
- 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
Google Scholar
- Jeremy Siek and Walid Taha. 2006. Gradual typing for functional languages. Scheme and Functional Programming, http://scheme2006.cs.uchicago.edu/13-siek.pdf
Google Scholar
- 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
Google Scholar
Cross Ref
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Cross Ref
- 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
Google Scholar
Cross Ref
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
- 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
Google Scholar
Digital Library
Index Terms
Live Pattern Matching with Typed Holes
Recommendations
Live functional programming with typed holes
Live programming environments aim to provide programmers (and sometimes audiences) with continuous feedback about a program's dynamic behavior as it is being edited. The problem is that programming languages typically assign dynamic meaning only to ...
Typed self-interpretation by pattern matching
ICFP '11: Proceedings of the 16th ACM SIGPLAN international conference on Functional programmingSelf-interpreters can be roughly divided into two sorts: self-recognisers that recover the input program from a canonical representation, and self-enactors that execute the input program. Major progress for statically-typed languages was achieved in ...
Typed self-interpretation by pattern matching
ICFP '11Self-interpreters can be roughly divided into two sorts: self-recognisers that recover the input program from a canonical representation, and self-enactors that execute the input program. Major progress for statically-typed languages was achieved in ...






Comments