Exact Support of the Free Monad #
The free monad FreeM P carries a canonical MonadAttach instance: the possible outputs of
a program are the leaf payloads reachable by choosing some direction at every operation
node,
and attach decorates each leaf with its reachability proof by structural recursion. Both
are computable and axiom-free, so MonadAttach.pbind is available for well-founded
recursion over free programs.
The instance is lawful, and structural induction also proves the pure and bind introduction
rules of ExactMonadAttach. MonadAttach.support on FreeM P reduces
definitionally — support (pure x) = {x} and support (liftBind a r) = ⋃ b, support (r b)
are both rfl — and the judgments AllOutputs/SomeOutput/NoOutput recurse structurally
over trees.
Two coherence results connect this to the rest of the library:
support_eq_range_output identifies the support with the range of FreeM.output over the
canonical FreeM.Path type, and support_eq_liftM_univ identifies it with the fold of the
"every response possible" handler into the powerset monad.
The structural support of a free tree: every direction of every operation node is possible.
Instances For
The structural support is the strongest postcondition: anything reachable in a tree of refined values satisfies the refinement.
Structural equations #
MonadAttach.support on FreeM P unfolds to supp, so the leaf and node equations hold by
rfl.
A primitive operation followed by a continuation can return any child output.
Mapping a free tree maps its reachable leaves, independently of result universes.
An operation object can return exactly the outputs of its continuation.
A free program has a possible return when every operation has an answer.
A free program has finitely many possible returns when every answer type is finite.
Structural recursion for the satisfaction judgments #
Coherence with paths and with the powerset fold #
The support is exactly the set of leaf payloads reachable along a canonical root-to-leaf path.
The support is the powerset-monad interpretation of the "every response possible" handler — the shape a support-as-fold presentation expects.
Every possible output is witnessed by a path, and conversely.
Some possible output is witnessed by a path, and conversely.