-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcross_handler_reversibility.007
More file actions
30 lines (28 loc) · 1.17 KB
/
Copy pathcross_handler_reversibility.007
File metadata and controls
30 lines (28 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- SPDX-License-Identifier: MPL-2.0
-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath)
--
-- Example: cross-handler reversibility (Layer 10 rung 3b, static half).
--
-- A `reversible as <name>` block in one handler binds an echo residue that a
-- `reverse <name>` in ANOTHER handler of the same agent can replay — the
-- residue is carried through agent state. This is the cross-handler counterpart
-- to the within-body named residues of rung 3a (see named_reversibility.007).
--
-- The type checker accepts the cross-handler `reverse undo` by PRESENCE: some
-- handler of this agent declares `reversible as undo`. The once-only / linear
-- discipline across handlers is a RUNTIME property — handler firing order is
-- not statically known (cf. `takeForReverse : Maybe` in EchoResidueLinear.idr).
agent ReversibleWorker {
control {
-- The happy path binds an undo capability under the name `undo`.
on receive(amount: Int) {
reversible as undo {
let snapshot = amount
}
}
-- On failure, a DIFFERENT handler replays it by name.
on error(reason: String) {
reverse undo
}
}
}