ABSTRACT
Structure editors allow programmers to edit the tree structure of a program directly. This can have cognitive benefits, particularly for novice and end-user programmers. It also simplifies matters for tool designers, because they do not need to contend with malformed program text.
This paper introduces Hazelnut, a structure editor based on a small bidirectionally typed lambda calculus extended with holes and a cursor. Hazelnut goes one step beyond syntactic well-formedness: its edit actions operate over statically meaningful incomplete terms. Naïvely, this would force the programmer to construct terms in a rigid "outside-in" manner. To avoid this problem, the action semantics automatically places terms assigned a type that is inconsistent with the expected type inside a hole. This meaningfully defers the type consistency check until the term inside the hole is finished.
Hazelnut is not intended as an end-user tool itself. Instead, it serves as a foundational account of typed structure editing. To that end, we describe how Hazelnut's rich metatheory, which we have mechanized using the Agda proof assistant, serves as a guide when we extend the calculus to include binary sum types. We also discuss various interpretations of holes, and in so doing reveal connections with gradual typing and contextual modal type theory, the Curry-Howard interpretation of contextual modal logic. Finally, we discuss how Hazelnut's semantics lends itself to implementation as an event-based functional reactive program. Our simple reference implementation is written using js_of_ocaml.
- Typed holes in GHC. https://wiki.haskell.org/GHC/Typed_ holes. Retrieved Nov. 7, 2016.Google Scholar
- A. Altadmri and N. C. Brown. 37 Million Compilations: Investigating Novice Programming Mistakes in Large-Scale Student Data. In ACM Technical Symposium on Computer Science Education (SIGCSE), 2015. Google ScholarDigital Library
- L. E. d. S. Amorim, S. Erdweg, G. Wachsmuth, and E. Visser. Principled syntactic code completion using placeholders. In SLE, 2016. Google ScholarDigital Library
- V. Balat. Ocsigen: Typing Web Interaction with Objective Caml. In ACM Workshop on ML, 2006. Google ScholarDigital Library
- P. Borras, D. Clément, T. Despeyroux, J. Incerpi, G. Kahn, B. Lang, and V. Pascual. CENTAUR: The System. In Proceedings of the ACM SIGSOFT/SIGPLAN Software Engineering Symposium on Practical Software Development Environments, pages 14–24, 1988. Google ScholarDigital Library
- E. Brady. Idris, A General-Purpose Dependently Typed Programming Language: Design and Implementation. Journal of Functional Programming, 23(05):552–593, 2013.Google ScholarCross Ref
- S. Burckhardt, M. Fähndrich, P. de Halleux, S. McDirmid, M. Moskal, N. Tillmann, and J. Kato. It’s alive! continuous feedback in UI programming. In PLDI, 2013. Google ScholarDigital Library
- P. Chiusano. Unison. http://www.unisonweb.org/. Accessed: 2016-04-25.Google Scholar
- A. Chlipala, L. Petersen, and R. Harper. Strict bidirectional type checking. In ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI), 2005. Google ScholarDigital Library
- D. R. Christiansen. Bidirectional Typing Rules: A Tutorial. http:// davidchristiansen.dk/tutorials/bidirectional.pdf, 2013.Google Scholar
- M. Cimini and J. G. Siek. The gradualizer: a methodology and algorithm for generating gradual type systems. In POPL, 2016. Google ScholarDigital Library
- M. Conway, S. Audia, T. Burnette, D. Cosgrove, and K. Christiansen. Alice: Lessons Learned from Building a 3D System for Novices. In SIGCHI Conference on Human Factors in Computing Systems (CHI), 2000. Google ScholarDigital Library
- L. Damas and R. Milner. Principal type-schemes for functional programs. In POPL, 1982. Google ScholarDigital Library
- R. Davies and F. Pfenning. Intersection types and computational effects. In ICFP, 2000. Google ScholarDigital Library
- M. de Jonge, E. Nilsson-Nyman, L. C. L. Kats, and E. Visser. Natural and flexible error recovery for generated parsers. In SLE, 2009. Google ScholarDigital Library
- J. Dunfield and N. R. Krishnaswami. Complete and easy bidirectional typechecking for higher-rank polymorphism. In ICFP, 2013. Google ScholarDigital Library
- C. Elliott. Tangible Functional Programming. In ICFP, 2007. Google ScholarDigital Library
- R. Garcia and M. Cimini. Principal Type Schemes for Gradual Programs. In POPL, 2015. Google ScholarDigital Library
- R. Garcia, A. M. Clark, and E. Tanter. Abstracting gradual typing. In POPL, 2016. Google ScholarDigital Library
- D. B. Garlan and P. L. Miller. GNOME: An introductory programming environment based on a family of structure editors. In First ACM SIGSOFT/SIGPLAN Software Engineering Symposium on Practical Software Development Environments, 1984. Google ScholarDigital Library
- M. Gordon, R. Milner, L. Morris, M. Newey, and C. Wadsworth. A metalanguage for interactive proof in LCF. In POPL, 1978. Google ScholarDigital Library
- R. Harper. Practical Foundations for Programming Languages. 2nd edition, 2016. Google ScholarCross Ref
- R. Harper and C. Stone. A Type-Theoretic Interpretation of Standard ML. In Proof, Language and Interaction: Essays in Honour of Robin Milner. MIT Press, 2000. Google ScholarDigital Library
- G. J. Holzmann. Brace yourself. IEEE Software, 33(5):34–37, Sept 2016. ISSN 0740-7459.Google ScholarDigital Library
- G. Huet. The Zipper. Journal of Functional Programming, 7(5), Sept. 1997. Functional Pearl. Google ScholarDigital Library
- D. Jones. Developer beliefs about binary operator precedence. C Vu, 18(4):14–21, 2006.Google Scholar
- L. C. L. Kats, M. de Jonge, E. Nilsson-Nyman, and E. Visser. Providing rapid feedback in generated modular language environments: adding error recovery to scannerless generalized-LR parsing. In OOPSLA, 2009. Google ScholarDigital Library
- A. J. Ko and B. A. Myers. Barista: An Implementation Framework for Enabling New Tools, Interaction Techniques and Views in Code Editors. In SIGCHI Conference on Human Factors in Computing Systems (CHI), 2006. Google ScholarDigital Library
- D. K. Lee, K. Crary, and R. Harper. Towards a mechanized metatheory of Standard ML. In POPL, 2007. Google ScholarDigital Library
- S. Lee and D. P. Friedman. Enriching the Lambda Calculus with Contexts: Toward a Theory of Incremental Program Construction. In ICFP, 1996. Google ScholarDigital Library
- S. Lerner, S. R. Foster, and W. G. Griswold. Polymorphic blocks: Formalism-inspired UI for structured connectors. In ACM Conference on Human Factors in Computing Systems (CHI), 2015. Google ScholarDigital Library
- D. R. Licata and R. Harper. A Universe of Binding and Computation. In ICFP, 2009. Google ScholarDigital Library
- E. Lotem and Y. Chuchem. Project Lamdu. http://www.lamdu. org/. Accessed: 2016-04-08.Google Scholar
- G. Marceau, K. Fisler, and S. Krishnamurthi. Do values grow on trees?: Expression integrity in functional programming. In Seventh International Workshop on Computing Education Research (ICER), 2011. Google ScholarDigital Library
- C. McBride. Dependently typed functional programs and their proofs. PhD thesis, University of Edinburgh. College of Science and Engineering. School of Informatics., 2000.Google Scholar
- T. Mens and T. Tourwé. A survey of software refactoring. IEEE Transactions on Software Engineering, 30(2):126–139, 2004. Google ScholarDigital Library
- R. Milner, M. Tofte, R. Harper, and D. MacQueen. The Definition of Standard ML (Revised). The MIT Press, 1997. Google ScholarDigital Library
- M. Minsky. Form and content in computer science (1970 ACM Turing Lecture). J. ACM, 17(2):197–215, 1970. Google ScholarDigital Library
- M. Mooty, A. Faulring, J. Stylos, and B. A. Myers. Calcite: Completing code completion for constructors using crowds. In IEEE Symposium on Visual Languages and Human-Centric Computing (VL/HCC), 2010. Google ScholarDigital Library
- A. Nanevski, F. Pfenning, and B. Pientka. Contextual modal type theory. ACM Trans. Comput. Log., 9(3), 2008. Google ScholarDigital Library
- 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 Scholar
- M. Odersky, C. Zenger, and M. Zenger. Colored local type inference. In POPL, 2001. Google ScholarDigital Library
- C. Omar, Y. Yoon, T. D. LaToza, and B. A. Myers. Active code completion. In ICSE, 2012. Google ScholarDigital Library
- C. Omar, D. Kurilova, L. Nistor, B. Chung, A. Potanin, and J. Aldrich. Safely composable type-specific languages. In ECOOP, 2014. Google ScholarDigital Library
- P. Osera and S. Zdancewic. Type-and-example-directed program synthesis. In PLDI, 2015. Google ScholarDigital Library
- B. Pientka. Beluga: Programming with dependent types, contextual data, and contexts. In International Symposium on Functional and Logic Programming (FLOPS), 2010. Google ScholarDigital Library
- B. C. Pierce and D. N. Turner. Local type inference. ACM Trans. Program. Lang. Syst., 22(1):1–44, Jan. 2000. Google ScholarDigital Library
- N. Pouillard. Nameless, painless. In ICFP, 2011. Google ScholarDigital Library
- A. Rastogi, A. Chaudhuri, and B. Hosmer. The ins and outs of gradual type inference. In POPL, 2012. Google ScholarDigital Library
- T. Reps and T. Teitelbaum. The synthesizer generator. SIGSOFT Softw. Eng. Notes, 9(3):42–48, Apr. 1984. ISSN 0163-5948. Google ScholarDigital Library
- M. Resnick, J. Maloney, A. Monroy-Hernández, N. Rusk, E. Eastmond, K. Brennan, A. Millner, E. Rosenbaum, J. Silver, B. Silverman, and Y. Kafai. Scratch: Programming for All. Commun. ACM, 52(11):60–67, Nov. 2009. Google ScholarDigital Library
- D. Sands. Computing with contexts: A simple approach. Electr. Notes Theor. Comput. Sci., 10:134–149, 1997. Google ScholarDigital Library
- A. Sarkar. The impact of syntax colouring on program comprehension. In Annual Conference of the Psychology of Programming Interest Group (PPIG), 2015.Google Scholar
- J. G. Siek and W. Taha. Gradual typing for functional languages. In Scheme and Functional Programming Workshop, 2006.Google Scholar
- R. J. Simmons and F. Pfenning. Weak Focusing for Ordered Linear Logic. Technical Report CMU-CS-10-147, Carnegie Mellon University, 2011. Revision of April 2011.Google Scholar
- A. Stefik and S. Siebert. An empirical investigation into programming language syntax. ACM Transactions on Computing Education (TOCE), 13(4):19, 2013. Google ScholarDigital Library
- B. Sufrin. Formal specification of a display-oriented text editor. Sci. Comput. Program., 1(3):157–202, 1982.Google ScholarCross Ref
- B. Sufrin and O. De Moor. Modeless structure editing. In Proceedings of the Oxford-Microsoft Symposium in Celebration of the work of Tony Hoare, 1999.Google Scholar
- T. Teitelbaum and T. Reps. The Cornell Program Synthesizer: A Syntaxdirected Programming Environment. Commun. ACM, 24(9):563–573, 1981. Google ScholarDigital Library
- N. Tillmann, M. Moskal, J. de Halleux, and M. Fahndrich. TouchDevelop: Programming Cloud-connected Mobile Devices via Touchscreen. In SIGPLAN Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software, 2011. Google ScholarDigital Library
- C. Urban, S. Berghofer, and M. Norrish. Barendregt’s variable convention in rule inductions. In Conference on Automated Deduction (CADE), 2007. Google ScholarDigital Library
- M. Voelter. Language and IDE Modularization and Composition with MPS. In International Summer School on Generative and Transformational Techniques in Software Engineering, pages 383–430. Springer, 2011.Google Scholar
- M. Voelter, D. Ratiu, B. Schaetz, and B. Kolb. Mbeddr: An Extensible C-based Programming Language and IDE for Embedded Systems. In SPLASH, 2012. Google ScholarDigital Library
- M. Voelter, J. Siegmund, T. Berger, and B. Kolb. Towards User-Friendly Projectional Editors. In International Conference on Software Language Engineering (SLE), 2014.Google Scholar
- M. Voelter, J. Warmer, and B. Kolb. Projecting a Modular Future. IEEE Software, 32(5):46–52, 2015.Google ScholarDigital Library
- Z. Wan and P. Hudak. Functional Reactive Programming from First Principles. In PLDI, 2000. Google ScholarDigital Library
- Y. S. Yoon and B. A. Myers. A longitudinal study of programmers’ backtracking. In IEEE Symposium on Visual Languages and Human-Centric Computing (VL/HCC), 2014.Google ScholarCross Ref
- B. Ziliani, D. Dreyer, N. R. Krishnaswami, A. Nanevski, and V. Vafeiadis. Mtac: A monad for typed tactic programming in Coq. Journal of Functional Programming, 25:e12, 2015. Google ScholarDigital Library
Index Terms
- Hazelnut: a bidirectionally typed structure editor calculus
Recommendations
Hazelnut: a bidirectionally typed structure editor calculus
POPL '17Structure editors allow programmers to edit the tree structure of a program directly. This can have cognitive benefits, particularly for novice and end-user programmers. It also simplifies matters for tool designers, because they do not need to contend ...
A Typed Lambda Calculus with Gradual Intersection Types
PPDP '22: Proceedings of the 24th International Symposium on Principles and Practice of Declarative ProgrammingIntersection types have the power to type expressions which are all of many different types. Gradual types combine type checking at both compile-time and run-time. Here we combine these two approaches in a new typed calculus that harness both of their ...
Interpretations of the gradually-typed lambda calculus
Scheme '12: Proceedings of the 2012 Annual Workshop on Scheme and Functional ProgrammingGradual typing is an approach to integrating static and dynamic type checking within the same language [Siek and Taha 2006]. Given the name "gradual typing", one might think that the most interesting aspect is the type system. It turns out that the ...
Comments