Branch paths and telescopes for PFunctor.FreeM #
This file contains the path-dependent structure that lives on top of the basic free monad on a polynomial functor.
For a polynomial/container P, PFunctor.FreeM P α is the inductive type of
well-founded P-branching trees with leaves labelled by α. The definitions
below isolate the branch-object pattern of such a tree:
FreeM.Path srecords an explicit polynomial direction at every node.FreeM.PathAlong l sis the canonical path throughs.mapLens l, i.e. the runtime branch through a control tree executed along a polynomial lens.FreeM.output s pathrecovers the leaf payload selected by that path.FreeM.append s kgrafts a suffix tree selected by the canonical path ofs.FreeM.TelescopeWithis the state-indexed initial algebra obtained by iterating such rounds, where the next state is selected by an abstract observation of the round.FreeM.Telescopeis the specialization where observations are canonical branch paths.
Terminology and references #
The same object appears under several names in the literature. In polynomial
functor language, the free monad on a polynomial is a type of terminating
decision trees. In container and W-type language, these are well-founded trees
and Path is the type of paths through such a tree. In dependent-type
presentations of games, these are dependent type trees and paths. In
programming language semantics, the coinductive analogue is an interaction
tree.
Relevant references include:
- Hancock and Setzer, Interactive Programs in Dependent Type Theory, for dependent I/O-trees over command-response worlds.
- Altenkirch, Ghani, Hancock, McBride, and Morris, Indexed Containers, for containers, indexed containers, and interaction structures.
- Libkind and Spivak, Pattern runs on matter, for free polynomial monads as terminating decision trees.
- Escardo and Oliva, Higher-order games with dependent types, for dependent type trees and paths in history-dependent games.
- Xia, Zakowski, He, Hur, Malecha, Pierce, and Zdancewic, Interaction Trees, for the coinductive programming-language analogue.
Canonical paths #
Displayed-family shape for canonical root-to-leaf paths.
Instances For
The canonical root-to-leaf path through a FreeM tree.
Instances For
Runtime paths along a lens #
Runtime path through a P-tree executed along a lens l : Lens P Q.
This is the displayed family over the source control tree whose node directions
come from the runtime polynomial Q. A runtime direction
d : Q.B (l.toFunA a) selects the source branch l.toFunB a d.
Instances For
Runtime path through a P-tree executed along a lens l : Lens P Q.
Instances For
The leaf payload selected by a path. Although the path itself records only
branch choices, the tree and path together determine the terminal pure
payload.
Instances For
The leaf payload selected by a runtime path along a lens.
Instances For
Constructor-local projection from runtime paths to control paths.
Instances For
Project a concrete runtime path along a lens back to the abstract canonical branch path of the control tree.
Instances For
Runtime paths and lens-mapped trees #
View a runtime path through s along l as the canonical path through the
lens-mapped runtime tree s.mapLens l.
The two types have the same constructor shape, but PathAlong is defined over
the source tree while Path (s.mapLens l) is defined over the lens-mapped tree.
Instances For
View a canonical path through the lens-mapped runtime tree s.mapLens l as a
runtime path through the original control tree s along l.
This is the inverse constructor-by-constructor view of
pathAlongToMapLensPath.
Instances For
Dependent sequential composition for FreeM trees using canonical paths.
Instances For
Canonical paths through appended trees #
Lift a two-argument family indexed by a canonical prefix path and canonical suffix path to a family on the appended tree.
Instances For
liftAppend on an appended canonical path reduces to the original
two-argument family.
Splitting after appending recovers the original canonical prefix and suffix.
Appending the components produced by split recovers the original
canonical path.
Transport a value of F path₁ path₂ to the liftAppend family at the
combined canonical path.
Instances For
Transport a value from the liftAppend family at an appended canonical path
back to the original two-argument family.
Instances For
liftAppend respects pointwise equality of the pair-indexed family.
A constant family is unaffected by liftAppend.
liftAppend can be reconstructed from the path pieces returned by split.
Reinterpret a liftAppend value against the path pair recovered by split.
Instances For
Collapse a liftAppend family indexed by append path₁ path₂ back to the
fused path index.
Instances For
Split a fused liftAppend product payload into separately lifted payloads.
Instances For
Fuse separately lifted payloads into a lifted product payload.
Instances For
When path = append path₁ path₂, the round-trip (packAppend then unliftAppend)
recovers the original pair-indexed relation value.
Lift a binary relation on pair-indexed families to the fused appended path.
Instances For
liftAppendRel applies R at the path pair recovered by split.
Lift a unary predicate on a pair-indexed family to the fused appended path.
Instances For
liftAppendPred applies the predicate at the path pair recovered by split.
Lens-executed paths through appended trees #
Lift a two-argument family indexed by a runtime prefix path and a runtime suffix path to a family on the appended tree.
The suffix is selected by the control projection of the runtime prefix.
Instances For
Combine a runtime prefix path and a runtime suffix path into a runtime path through the appended tree.
Instances For
Split a runtime path through an appended tree into its prefix runtime path and suffix runtime path.
Instances For
liftAppend on an appended runtime path reduces to the original
two-argument family.
Splitting after appending recovers the original runtime prefix and suffix.
Appending the components produced by split recovers the original runtime path.
Transport a value of F path₁ path₂ to the liftAppend family at the
combined runtime path. The definition follows the same recursion as
liftAppend, so it avoids explicit equality transports.
Instances For
Transport a value from the liftAppend family at an appended runtime path
back to the original two-argument family.
Instances For
liftAppend can be reconstructed from the runtime path pieces returned by split.
Reinterpret a runtime liftAppend value against the path pair recovered by split.
Instances For
Projecting an appended runtime path gives the appended projected paths.
Telescopes #
Initial-algebra presentation of a state-machine telescope of FreeM
rounds observed through an arbitrary observation family Obs.
At each state s, an inhabitant either terminates or extends by running
round s and recursing into the next state selected by an observation
obs : Obs s. The observation family is intentionally abstract: canonical
FreeM branch paths use Obs s = Path (round s), while quotiented or compact
views can erase uninformative singleton choices.
- done {P : PFunctor.{uA, uB}} {St : Type z} {Out : St → Type v} {round : (s : St) → P.FreeM (Out s)} {Obs : St → Type w} {step : (s : St) → Obs s → St} (s : St) : TelescopeWith round Obs step s
- extend {P : PFunctor.{uA, uB}} {St : Type z} {Out : St → Type v} {round : (s : St) → P.FreeM (Out s)} {Obs : St → Type w} {step : (s : St) → Obs s → St} (s : St) (cont : (obs : Obs s) → TelescopeWith round Obs step (step s obs)) : TelescopeWith round Obs step s
Instances For
Flatten a telescope into a single FreeM tree by iterated dependent
append, using appendRound to graft each observed round and finish at
terminal states.
Instances For
State-machine telescopes whose observations are canonical FreeM branch
paths. This is the default specialization of TelescopeWith; users with a
more compact observation type should use TelescopeWith directly.
Instances For
Constructor wrapper for terminating a canonical-path telescope.
Instances For
Constructor wrapper for extending a canonical-path telescope.
Instances For
Flatten a canonical-path telescope into a single FreeM tree by iterated
dependent append, using finish at terminal states.