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.StoppingTreeis the state-indexed initial algebra whose next state is selected by an abstract observation.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 algebra for canonical root-to-leaf paths.
Instances For
The canonical root-to-leaf path through a FreeM tree.
Instances For
The node interface #
A path through an operation node is a direction together with a path through the selected
child. cons, head and tail are the public interface to that structure; statements and
lemmas go through them rather than through the anonymous constructor and projections of the
underlying sigma type, so nothing outside this file depends on how Displayed unfolds. The
node is written in its simp normal form (FreeM.lift a).bind rest; the constructor spelling
FreeM.liftBind a rest produced by pattern matching is the same tree.
head on a path destructured by pattern matching. The path is not indexed: its hidden
sigma type reduces when the polynomial is concrete.
Two paths through a node agree once their directions and tails agree.
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 node interface #
The runtime analogue of Path.cons / Path.head / Path.tail: a runtime path through an
operation node is a runtime direction together with a runtime path through the source branch it
selects.
Prepend one runtime direction to a runtime path through the branch it selects.
Instances For
The runtime direction selected at the root of a non-leaf runtime path.
Instances For
The runtime path remaining below the root direction of a non-leaf runtime path.
Instances For
head on a runtime path destructured by pattern matching.
tail on a runtime path destructured by pattern matching.
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
Follow a fixed direction selector at every operation node to obtain a complete path through a free tree. The selector is operation-dependent, but does not inspect the continuation below the selected direction.
Instances For
Read the leaf selected by the unique direction of every node in a free
tree over the identity polynomial y.
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
Pull a canonical path through a lens-mapped tree back to the corresponding canonical path through the source tree.
Instances For
Pulling a mapped path directly agrees with first viewing it as a runtime path and then projecting it to the control tree.
Pull a path through a leaf-relabelled tree back to the original tree. Relabelling changes no operation-node directions.
Instances For
Dependent sequential composition for FreeM trees using canonical paths.
Instances For
Grafting a continuation selected only by the leaf payload is ordinary
free-monad bind. append is more general because its continuation may inspect
the entire path; this theorem identifies their exact overlap.
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
Associativity of path-indexed tree grafting. The suffix continuation on the right is reindexed by the path obtained by appending the outer and middle paths.
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.
Well-founded stopping trees #
Indexed W-type of stopping trees for a transition system observed through
an arbitrary family Obs.
At each state s, an inhabitant either stops or extends and recurses into the
next state selected by each observation obs : Obs s. Because done s is
available at every state, inhabitation alone does not assert termination of
the underlying transition system.
- done {St : Type z} {Obs : St → Type w} {step : (s : St) → Obs s → St} (s : St) : StoppingTree Obs step s
- extend {St : Type z} {Obs : St → Type w} {step : (s : St) → Obs s → St} (s : St) (cont : (obs : Obs s) → StoppingTree Obs step (step s obs)) : StoppingTree Obs step s
Instances For
An algebra for the indexed polynomial
y ↦ (fun s => PUnit ⊕ ((obs : Obs s) → y (step s obs))).
StoppingTree is its initial algebra: fold below is the unique algebra
homomorphism into any such carrier family.
- done (s : St) : Carrier s
Interpretation of a stopping leaf.
- extend (s : St) : ((obs : Obs s) → Carrier (step s obs)) → Carrier s
Interpretation of one transition layer.
Instances For
The catamorphism from the initial stopping-tree algebra.
Instances For
Uniqueness half of the initial-algebra universal property. Any function
respecting done and extend agrees pointwise with fold.
State-machine telescopes whose observations are canonical FreeM branch
paths. This is the round-indexed specialization of StoppingTree; users with
a more compact observation type should use StoppingTree 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.