一种面向时空可组合性的编程范式
观点分析 · 2026/08/27
现代软件(从插件系统到自我演化的智能体框架)越来越需要动态组合,但其形式化基础仍不完善。我们识别出问题的两个正交维度:时间组合性(移除组件时能完全撤销其副作用)和空间组合性(声明并响应式管理组件间依赖)。我们通过将经典效应(effect)和余效应(coeffect)概念提升为运行时机制来解决这两个维度。具体而言,我们形式化了可逆效应,其中每个上下文变换都带有运行时持有的逆变换,从而在单个组件局部建立时间组合性。我们形式化了响应式余效应,其中每个上下文变化都根据组件的余效应规范进行分类,以驱动其激活和停用,从而在单个组件局部建立空间组合性。然后我们将效应上下文和余效应上下文统一为单一上下文类型,并通过它中介所有效应和余效应,形成我们称为上下文范式的纪律;这种中介引发一种观测等价性,在此等价性下,不同组件的效应交错而不相互干扰。将这些机制组合成组件的概念,我们给出了动态组合的演算,其元理论将时空组合性从单个组件扩展到整个交错组件系统。我们在Cordis中实现了这些思想,Cordis是一个时空组合性的元框架,提供带有效应跟踪和余效应解析的核心库,以及带有配置协调和热模块替换的声明式组件加载器。
该论文针对动态组合缺乏形式化基础的问题,提出时空组合性概念,并给出统一的理论框架和实现,对插件系统、智能体框架等现代软件设计具有重要理论价值和实践意义。
Modern software -- from plugin systems to self-evolving agent harnesses -- increasingly requires dynamic composition, yet its formal foundations remain underdeveloped. We identify two orthogonal dimensions of the problem: temporal composability, the ability to completely revert a component's side effects upon removal, and spatial composability, the ability to declare and reactively manage inter-component dependencies. We address the two dimensions by lifting classical effect and coeffect concepts to runtime mechanisms. In particular, we formalize revertible effects, in which every context transformation carries an inverse that the runtime holds, establishing temporal composability local to one component. We formalize reactive coeffects, in which every context change is classified against a component's coeffect specification to drive its activation and deactivation, establishing spatial composability local to one component. We then unify the effect context and the coeffect context into a single context type and mediate every effect and coeffect through it, yielding a discipline we call the context paradigm; the mediation induces an observational equivalence up to which the effects of distinct components interleave without disturbing one another. Combining these mechanisms into the notion of a component, we give a calculus of dynamic composition whose metatheory carries spatiotemporal composability from a single component to a whole system of interleaved components. We implement these ideas in Cordis, a meta-framework of spatiotemporal composability that provides a core library with effect tracking and coeffect resolution, as well as a declarative component loader with configuration reconciliation and hot module replacement.