时空可组合性(Spatiotemporal Composability)
定义
Cordis 论文《A Programming Paradigm for Spatiotemporal Composability》提出的编程范式:把动态组合问题分解为时间可组合性与空间可组合性两个正交维度,分别用**可逆效应(revertible effects)与反应式共效应(reactive coeffects)**解决,最终统一为单一 context 类型。
核心要点
两个正交维度
- 时间可组合性(temporal composability):组件被移除时,其副作用能被完全回退。
“the ability to completely revert a component’s side effects upon removal”
- 空间可组合性(spatial composability):组件间依赖能被声明式表达并响应式管理。
“the ability to declare and reactively manage inter-component dependencies”
两个运行时机制
- 可逆效应(revertible effects):每次 context 变换都携带逆变换,由运行时追踪。→ 解决时间维度。
“every context transformation carries an inverse that the runtime tracks”
- 反应式共效应(reactive coeffects):context 每次变化,都按组件的 coeffect 规格通知该组件。→ 解决空间维度。
“each change of the context notifies a component against its coeffect specification”
统一:单一 context 类型
“We unify the effect context and the coeffect context into a single context type, which constitutes a programming paradigm.”
我们把「效应上下文」和「共效应上下文」统一成同一个 context 类型,这就构成了一种编程范式。
组件演算
“we combine these mechanisms into the notion of a component and give a calculus of dynamic composition, whose metatheory carries spatiotemporal composability from a single component to a whole system of interleaved components.”
我们把这两个机制合起来,形成了「组件」这个概念,并给出一套动态组合的演算规则。这套演算的意义在于:它能把时空可组合性从单个组件推广到一大堆互相交错的组件组成的整个系统。
与 DSH 的对应
| 论文机制 | DSH 落点 |
|---|---|
| 可逆效应 | ctx.effect() / ctx.on(),注册返回 disposer |
| 反应式共效应 | inject 依赖 + typed events |
| 单一 context 类型 | Cordis Context(ctx.<key>) |
| 组件演算 | 插件树(profile/bundle/patch) |
| 声明式加载 + 调和 | cordis.yml + patch 覆盖 |
| HMR | Creator mode 内存测试插件 |