skip to main content
10.1145/3009837.3009900acmconferencesArticle/Chapter ViewAbstractPublication PagespoplConference Proceedingsconference-collections
research-article
Public Access

Hazelnut: a bidirectionally typed structure editor calculus

Published:01 January 2017Publication History

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.

References

  1. Typed holes in GHC. https://wiki.haskell.org/GHC/Typed_ holes. Retrieved Nov. 7, 2016.Google ScholarGoogle Scholar
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. L. E. d. S. Amorim, S. Erdweg, G. Wachsmuth, and E. Visser. Principled syntactic code completion using placeholders. In SLE, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. V. Balat. Ocsigen: Typing Web Interaction with Objective Caml. In ACM Workshop on ML, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. E. Brady. Idris, A General-Purpose Dependently Typed Programming Language: Design and Implementation. Journal of Functional Programming, 23(05):552–593, 2013.Google ScholarGoogle ScholarCross RefCross Ref
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. P. Chiusano. Unison. http://www.unisonweb.org/. Accessed: 2016-04-25.Google ScholarGoogle Scholar
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. D. R. Christiansen. Bidirectional Typing Rules: A Tutorial. http:// davidchristiansen.dk/tutorials/bidirectional.pdf, 2013.Google ScholarGoogle Scholar
  11. M. Cimini and J. G. Siek. The gradualizer: a methodology and algorithm for generating gradual type systems. In POPL, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. L. Damas and R. Milner. Principal type-schemes for functional programs. In POPL, 1982. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. R. Davies and F. Pfenning. Intersection types and computational effects. In ICFP, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. J. Dunfield and N. R. Krishnaswami. Complete and easy bidirectional typechecking for higher-rank polymorphism. In ICFP, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. C. Elliott. Tangible Functional Programming. In ICFP, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. R. Garcia and M. Cimini. Principal Type Schemes for Gradual Programs. In POPL, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. R. Garcia, A. M. Clark, and E. Tanter. Abstracting gradual typing. In POPL, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. M. Gordon, R. Milner, L. Morris, M. Newey, and C. Wadsworth. A metalanguage for interactive proof in LCF. In POPL, 1978. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. R. Harper. Practical Foundations for Programming Languages. 2nd edition, 2016. Google ScholarGoogle ScholarCross RefCross Ref
  23. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  24. G. J. Holzmann. Brace yourself. IEEE Software, 33(5):34–37, Sept 2016. ISSN 0740-7459.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. G. Huet. The Zipper. Journal of Functional Programming, 7(5), Sept. 1997. Functional Pearl. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. D. Jones. Developer beliefs about binary operator precedence. C Vu, 18(4):14–21, 2006.Google ScholarGoogle Scholar
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. D. K. Lee, K. Crary, and R. Harper. Towards a mechanized metatheory of Standard ML. In POPL, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. S. Lee and D. P. Friedman. Enriching the Lambda Calculus with Contexts: Toward a Theory of Incremental Program Construction. In ICFP, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  32. D. R. Licata and R. Harper. A Universe of Binding and Computation. In ICFP, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. E. Lotem and Y. Chuchem. Project Lamdu. http://www.lamdu. org/. Accessed: 2016-04-08.Google ScholarGoogle Scholar
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  35. C. McBride. Dependently typed functional programs and their proofs. PhD thesis, University of Edinburgh. College of Science and Engineering. School of Informatics., 2000.Google ScholarGoogle Scholar
  36. T. Mens and T. Tourwé. A survey of software refactoring. IEEE Transactions on Software Engineering, 30(2):126–139, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. R. Milner, M. Tofte, R. Harper, and D. MacQueen. The Definition of Standard ML (Revised). The MIT Press, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. M. Minsky. Form and content in computer science (1970 ACM Turing Lecture). J. ACM, 17(2):197–215, 1970. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  40. A. Nanevski, F. Pfenning, and B. Pientka. Contextual modal type theory. ACM Trans. Comput. Log., 9(3), 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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
  42. M. Odersky, C. Zenger, and M. Zenger. Colored local type inference. In POPL, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. C. Omar, Y. Yoon, T. D. LaToza, and B. A. Myers. Active code completion. In ICSE, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. C. Omar, D. Kurilova, L. Nistor, B. Chung, A. Potanin, and J. Aldrich. Safely composable type-specific languages. In ECOOP, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. P. Osera and S. Zdancewic. Type-and-example-directed program synthesis. In PLDI, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. B. Pientka. Beluga: Programming with dependent types, contextual data, and contexts. In International Symposium on Functional and Logic Programming (FLOPS), 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. B. C. Pierce and D. N. Turner. Local type inference. ACM Trans. Program. Lang. Syst., 22(1):1–44, Jan. 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. N. Pouillard. Nameless, painless. In ICFP, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. A. Rastogi, A. Chaudhuri, and B. Hosmer. The ins and outs of gradual type inference. In POPL, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. T. Reps and T. Teitelbaum. The synthesizer generator. SIGSOFT Softw. Eng. Notes, 9(3):42–48, Apr. 1984. ISSN 0163-5948. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  52. D. Sands. Computing with contexts: A simple approach. Electr. Notes Theor. Comput. Sci., 10:134–149, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. A. Sarkar. The impact of syntax colouring on program comprehension. In Annual Conference of the Psychology of Programming Interest Group (PPIG), 2015.Google ScholarGoogle Scholar
  54. J. G. Siek and W. Taha. Gradual typing for functional languages. In Scheme and Functional Programming Workshop, 2006.Google ScholarGoogle Scholar
  55. 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 ScholarGoogle Scholar
  56. A. Stefik and S. Siebert. An empirical investigation into programming language syntax. ACM Transactions on Computing Education (TOCE), 13(4):19, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  57. B. Sufrin. Formal specification of a display-oriented text editor. Sci. Comput. Program., 1(3):157–202, 1982.Google ScholarGoogle ScholarCross RefCross Ref
  58. 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 ScholarGoogle Scholar
  59. T. Teitelbaum and T. Reps. The Cornell Program Synthesizer: A Syntaxdirected Programming Environment. Commun. ACM, 24(9):563–573, 1981. Google ScholarGoogle ScholarDigital LibraryDigital Library
  60. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  61. C. Urban, S. Berghofer, and M. Norrish. Barendregt’s variable convention in rule inductions. In Conference on Automated Deduction (CADE), 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  62. 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 ScholarGoogle Scholar
  63. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  64. M. Voelter, J. Siegmund, T. Berger, and B. Kolb. Towards User-Friendly Projectional Editors. In International Conference on Software Language Engineering (SLE), 2014.Google ScholarGoogle Scholar
  65. M. Voelter, J. Warmer, and B. Kolb. Projecting a Modular Future. IEEE Software, 32(5):46–52, 2015.Google ScholarGoogle ScholarDigital LibraryDigital Library
  66. Z. Wan and P. Hudak. Functional Reactive Programming from First Principles. In PLDI, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  67. 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 ScholarGoogle ScholarCross RefCross Ref
  68. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Hazelnut: a bidirectionally typed structure editor calculus

      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
      • Published in

        cover image ACM Conferences
        POPL '17: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages
        January 2017
        901 pages
        ISBN:9781450346603
        DOI:10.1145/3009837

        Copyright © 2017 ACM

        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: 1 January 2017

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

        Acceptance Rates

        Overall Acceptance Rate824of4,130submissions,20%

        Upcoming Conference

        POPL '25

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader