Free Monad of a Polynomial Functor #
PolyFun's layer over cslib's free monad PFunctor.FreeM: the W-type presentations, root
predicates, transport along lenses, and the bundled monad-homomorphism form of FreeM.liftM
with its universal property and naturality. The algebraic laws (map_pure, map_bind, foldFreeM,
foldFreeM_bind, liftM_comp, liftM_lift_eq_self) are staged for cslib in
ToCslib.Data.PFunctor.Free.Basic, which this module re-exports.
Simp set for structurally unfolding FreeM and displayed-family operations.
This set is reserved for one-way unfolding lemmas: constructor equations for
FreeM operations, displayed-family operations, and local-hom recursion through
liftBind. Folding and normalization lemmas should not be tagged with this
attribute.
Instances For
Fixed-point presentation #
Reinterpret a finite free program as the W-type of query-or-return nodes. Query nodes are the left summand and return nodes are nullary nodes in the constant right summand.
Instances For
Decode the query-or-return W-type as a finite free program.
Instances For
FreeM P α is the initial algebra, or W-type, for the polynomial
P + C α.
Instances For
Test only the root of a free polynomial tree.
A leaf demands leafPred of its result, while an internal node demands
positionPred of its exposed position. This deliberately does not recurse
into the continuations; callers can quantify over paths or cursors when they
need a whole-tree property.
Instances For
Forward direction of the equivalence with P.W when the leaf type is empty: every pure
case is unreachable, and every liftBind is reinterpreted as a W-node.
Instances For
Inverse direction of the equivalence with P.W when the leaf type is empty: every W-node
becomes a liftBind.
Instances For
When the value type is empty, every pure is unreachable and FreeM P α is structurally
identical to P.W.
Instances For
Transport a free polynomial tree along a polynomial lens.
The source polynomial P is the abstract/control interface. The target
polynomial Q is the concrete/runtime interface. At each P-node, the lens
chooses a Q-position by toFunA; when runtime supplies a Q-direction,
toFunB maps it back to the corresponding P-direction selecting the
control continuation.
Instances For
FreeM.liftM as a monad homomorphism.
Instances For
FreeM.liftM as a monad homomorphism, packaging the interpretation of
positions as a natural transformation NatHom P.Obj m.
Instances For
Universal property and naturality of the fold #
FreeM.liftM s is the universal fold: the unique monad homomorphism out of FreeM P extending a
handler s (liftMHom_unique), and it is natural in the target monad — post-composing with a
monad morphism φ : m →ᵐ n is the fold of the post-composed handler (liftM_natural,
liftMHom_comp). This is the freeness of FreeM P; downstream it lets a semantic monad morphism
(e.g. an evaluation-distribution map) be pushed through a fold uniformly, rather than re-run by
induction per interpretation.
Universal property of FreeM.liftM (freeness of FreeM P): a monad homomorphism out of
FreeM P is determined by its action on generators. If F : FreeM P →ᵐ m agrees with s on every
FreeM.lift a, then F = FreeM.liftMHom s. So handlers (a : P.A) → m (P.B a) are in bijection
with monad homomorphisms FreeM P →ᵐ m — the universal property behind simulateQ.
Naturality of the fold along a monad morphism: pushing a monad morphism φ : m →ᵐ n through
FreeM.liftM s is the fold of the post-composed handler fun a => φ (s a) — the value-level
naturality square of the universal fold.
Bundled form of liftM_natural: composing the fold monad-homomorphism FreeM.liftMHom s with
a monad morphism φ is the fold of the post-composed handler.
Stateful naturality of the fold: running a fold whose stateful handler is post-composed by
a StateT-lifted monad morphism StateT.mapHom φ is φ applied to the run of the original fold —
the shape a StateT-threaded semantic morphism (e.g. an evaluation-distribution map through a
stateful handler) instantiates, collapsing a per-interpretation induction to one use of
liftM_natural.