一句话:提出带类型洞的不完整函数式程序动态语义,求值可绕过洞并支持填洞后恢复,已在Agda机器化并实现于Hazel。
实时编程环境希望随编辑持续反馈动态行为,但传统语言只对完整且类型正确的程序赋予动态意义,造成反馈缺口。本文从类型论第一原理出发,为不完整函数式程序建立动态语义:程序是带洞表达式,空穴表示缺失表达式或类型,非空穴作为类型不一致的膜;求值绕过洞并跟踪洞实例的闭包。洞闭包支持编辑器服务理解程序,并支持填洞后恢复求值。语义结合渐进类型论与上下文模态类型论,保持类型安全。作者在Agda中机器化Hazelnut Live,并在Hazel中实现,保证每个可达编辑状态都有(可能不完整的)类型,实现无缺口反馈。
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 programs that are complete, i.e. syntactically well-formed and free of type errors. Consequently, live feedback presented to the programmer exhibits temporal or perceptive gaps. This paper confronts this "gap problem" from type-theoretic first principles by developing a dynamic semantics for incomplete functional programs, starting from the static semantics for incomplete functional programs developed in recent work on Hazelnut. We model incomplete functional programs as expressions with holes, with empty holes standing for missing expressions or types, and non-empty holes operating as membranes around static and dynamic type inconsistencies. Rather than aborting when evaluation encounters any of these holes as in some existing systems, evaluation proceeds around holes, tracking the closure around each hole instance as it flows through the remainder of the program. Editor services can use the information in these hole closures to help the programmer develop and confirm their mental model of the behavior of the complete portions of the program as they decide how to fill the remaining holes. Hole closures also enable a fill-and-resume operation that avoids the need to restart evaluation after edits that amount to hole filling. Formally, the semantics borrows machinery from both gradual type theory (which supplies the basis for handling unfilled type holes) and contextual modal type theory (which supplies a logical basis for hole closures), combining these and developing additional machinery necessary to continue evaluation past holes while maintaining type safety. We have mechanized the metatheory of the core calculus, called Hazelnut Live, using the Agda proof assistant. We have also implemented these ideas into the Hazel programming environment. The implementation inserts holes automatically, following the Hazelnut edit action calculus, to guarantee that every editor state has some (possibly incomplete) type. Taken together with this paper's type safety property, the result is a proof-of-concept live programming environment where rich dynamic feedback is truly available without gaps, i.e. for every reachable editor state.
@article{paperbot641,
title = {Live functional programming with typed holes},
author = {Cyrus Omar and Ian Voysey and Ravi Chugh and Matthew A. Hammer},
journal = {Proceedings of the ACM on Programming Languages},
volume = {3},
number = {POPL},
year = {2019},
doi = {10.1145/3290327}
}