arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2403.02296cs.PL
收藏

无函数的响应式编程

Reactive Programming without Functions

Bjarno Oeyen, Joeri De Koster, Wolfgang De Meuter

AI总结:

本文提出一种无函数、无提升的纯响应式编程语言,以 reactors 与 deployments 为核心并增量引入状态、动态依赖、递归和词法作用域,从而避免 EDSL 中宿主代码带来的发散与范式失配问题。

摘要:

背景:响应式编程(RP)是一种适合表达事件处理的声明式编程范式。它使程序员能够创建随时间变化自动作出反应的应用程序。每当随时间变化的信号发生改变时——例如响应事件流产生的值(如传感器数据、用户输入……)——程序状态就会随该变化自动更新。这使得 RP 非常适合构建交互式应用程序和响应式(软实时)系统。\n问题:RP 语言实现通常作为嵌入式领域特定语言(EDSL)构建在现有(宿主)语言之上。这导致应用程序代码中的响应式代码与非响应式代码不可避免地纠缠在一起。通过一种称为提升(lifting)的机制,人们通常可以在 RP 程序中使用(非响应式)宿主语言的全部功能。然而,提升也很危险。首先,以图灵完备语言表达的宿主代码可能发散,导致程序无响应:即响应式程序实际上并不具有响应性。其次,响应式代码与非响应式代码的双向集成会造成范式失配;若不加约束,会导致程序出现错误行为。\n方法:我们提出一种新的响应式编程语言,经过精心设计,仅支持响应式。我们从一个简单的(一阶)响应式模型开始,该模型基于 reactors(即信号及其依赖关系的未实例化描述)和由信号组成的 deployments(即 reactors 的实例)。该语言没有函数概念,因此与其他 RP 语言不同,它也没有提升。我们以增量方式用其他编程语言(无论是否为 RP 语言)中的附加特性扩展这个简单模型。这些特性包括:有状态 reactors(允许基于时间的累积)、通过条件语句实现动态依赖的信号和多态 deployments、递归定义的 reactors,以及具有词法作用域的(匿名)reactors。\n知识:在描述这些语言特性时,我们不仅描述语法和语义,还说明每个特性与(EDSL)RP 语言中存在的问题相比如何。也就是说,通过从纯响应式模型出发,我们识别出哪些响应式特性(在其他 RP 语言中通常用非响应式代码表达)会影响该语言能够强制保证的响应式性质。\n依据:我们通过分析每个特性对本语言的影响来支撑论点:例如,分析信号如何更新、如何创建,以及信号之间的依赖关系如何受到影响。在适用情况下,我们会与其他语言进行类比:即突出并深入分析与其他 RP 语言共有的相似之处,并在相关时对非响应式语言进行同样的分析。\n重要性:我们的语言展示了纯响应式编程如何能够表达与其他需要使用(未经检查的)函数的 RP 语言相同类型的程序。通过将响应式程序视为纯(仅响应式)reactors 的集合,我们旨在增进语言设计者和用户对响应式编程的理解。

英文摘要:

Context: Reactive programming (RP) is a declarative programming paradigm suitable for expressing the handling of events. It enables programmers to create applications that react automatically to changes over time. Whenever a time-varying signal changes -- e.g. in response to values produced by event stream (e.g., sensor data, user input...) -- the program state is updated automatically in tandem with that change. This makes RP well-suited for building interactive applications and reactive (soft real-time) systems. Inquiry: RP Language implementations are often built on top of an existing (host) language as an Embedded Domain Specific Language (EDSL). This results in application code in which reactive code and non-reactive code is inherently entangled. Using a mechanism known as lifting, one usually has access to the full feature set of the (non-reactive) host language in the RP program. However, lifting is also dangerous. First, host code expressed in a Turing-complete language may diverge, resulting in unresponsive programs: i.e. reactive programs that are not actually reactive. Second, the bi-directional integration of reactive and non-reactive code results in a paradigmatic mismatch that, when unchecked, leads to faulty behaviour in programs. Approach: We propose a new reactive programming language, that has been meticulously designed to be reactive-only. We start with a simple (first-order) model for reactivity, based on reactors (i.e. uninstantiated descriptions of signals and their dependencies) and deployments (i.e. instances of reactors) that consist of signals. The language does not have the notion of functions, and thus unlike other RP languages there is no lifting either. We extend this simple model incrementally with additional features found in other programming languages, RP or otherwise. These features include stateful reactors (that allow for time-based accumulation), signals with dynamic dependencies by means of conditionals and polymorphic deployments, recursively-defined reactors, and (anonymous) reactors with lexical scope. Knowledge: In our description of these language features, we not only describe the syntax and semantics, but also how each features compares to the problems that exist in (EDSL) RP languages. I.e. by starting from a reactive-only model, we identify which reactive features (that, in other RP languages are typically expressed in non-reactive code) affect the reactive guarantees that can be enforced by the language. Grounding: We base our arguments by analysing the effect that each feature has on our language: e.g., by analysing how signals are updated, how they are created and how dependencies between signals can be affected. When applicable, we draw parallels with other languages: i.e. similarities shared with other RP languages will be highlighted and thoroughly analysed, and where relevant the same will also be done with non-reactive languages. Importance: Our language shows how a purely reactive programming is able to express the same kinds of programs as in other RP languages that require the use of (unchecked) functions. By considering reactive programs as a collection of pure (reactive-only) reactors, we aim to increase how reactive programming is comprehended by both language designers and its users.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑