The M construction as a multivariate polynomial functor. #
M types are potentially infinite tree-like structures. They are defined as the greatest fixpoint of a polynomial functor.
Main definitions #
M.mk
- constructorM.dest
- destructorM.corec
- corecursor: useful for formulating infinite, productive computationsM.bisim
- bisimulation: proof technique to show the equality of infinite objects
Implementation notes #
Dual view of M-types:
Specifically, we define the polynomial functor mp
as:
- A := a possibly infinite tree-like structure without information in the nodes
- B := given the tree-like structure
t
,B t
is a valid path from the root oft
to any given node.
As a result mp α
is made of a dataless tree and a function from
its valid paths to values of α
The difference with the polynomial functor of an initial algebra is
that A
is a possibly infinite tree.
Reference #
- Jeremy Avigad, Mario M. Carneiro and Simon Hudon. [Data Types as Quotients of Polynomial Functors][avigad-carneiro-hudon2019]
A path from the root of a tree to one of its node
- root: {n : ℕ} → {P : MvPFunctor.{u} (n + 1)} → (x : P.last.M) → (a : P.A) → (f : P.last.B a → P.last.M) → x.dest = ⟨a, f⟩ → (i : Fin2 n) → P.drop.B a i → MvPFunctor.M.Path P x i
- child: {n : ℕ} → {P : MvPFunctor.{u} (n + 1)} → (x : P.last.M) → (a : P.A) → (f : P.last.B a → P.last.M) → x.dest = ⟨a, f⟩ → (j : P.last.B a) → (i : Fin2 n) → MvPFunctor.M.Path P (f j) i → MvPFunctor.M.Path P x i
Instances For
Equations
- MvPFunctor.M.Path.inhabited P x = { default := MvPFunctor.M.Path.root x x.head x.children ⋯ i default }
Polynomial functor of the M-type of P
. A
is a data-less
possibly infinite tree whereas, for a given a : A
, B a
is a valid
path in tree a
so that mp α
is made of a tree and a function
from its valid paths to the values it contains
Equations
- P.mp = { A := P.last.M, B := MvPFunctor.M.Path P }
Instances For
Equations
- P.inhabitedM = MvPFunctor.Obj.inhabited P.mp
construct through corecursion the shape of an M-type without its contents
Equations
- MvPFunctor.M.corecShape P g₀ g₂ = PFunctor.M.corec fun (b : β) => ⟨g₀ b, g₂ b⟩
Instances For
Proof of type equality as an arrow
Instances For
Proof of type equality as a function
Instances For
Using corecursion, construct the contents of an M-type
Equations
- MvPFunctor.M.corecContents P g₀ g₁ g₂ x✝ b h x (MvPFunctor.M.Path.root x✝ a f h' x c) = g₁ b x (P.castDropB ⋯ x c)
- MvPFunctor.M.corecContents P g₀ g₁ g₂ x✝ b h x (MvPFunctor.M.Path.child x✝ a f h' j x c) = MvPFunctor.M.corecContents P g₀ g₁ g₂ (f j) (g₂ b (P.castLastB ⋯ j)) ⋯ x c
Instances For
Corecursor for M-type of P
Equations
- MvPFunctor.M.corec' P g₀ g₁ g₂ b = ⟨MvPFunctor.M.corecShape P g₀ g₂ b, MvPFunctor.M.corecContents P g₀ g₁ g₂ (MvPFunctor.M.corecShape P g₀ g₂ b) b ⋯⟩
Instances For
Corecursor for M-type of P
Equations
- MvPFunctor.M.corec P g = MvPFunctor.M.corec' P (fun (b : β) => (g b).fst) (fun (b : β) => TypeVec.dropFun (g b).snd) fun (b : β) => TypeVec.lastFun (g b).snd
Instances For
Implementation of destructor for M-type of P
Equations
- MvPFunctor.M.pathDestLeft P h f' i c = f' i (MvPFunctor.M.Path.root x a f h i c)
Instances For
Implementation of destructor for M-type of P
Equations
- MvPFunctor.M.pathDestRight P h f' j i c = f' i (MvPFunctor.M.Path.child x a f h j i c)
Instances For
Destructor for M-type of P
Equations
- MvPFunctor.M.dest' P h f' = ⟨a, TypeVec.splitFun (MvPFunctor.M.pathDestLeft P h f') fun (x_1 : (P.B a).last) => ⟨f x_1, MvPFunctor.M.pathDestRight P h f' x_1⟩⟩
Instances For
Destructor for M-types
Equations
- MvPFunctor.M.dest P x = MvPFunctor.M.dest' P ⋯ x.snd
Instances For
Constructor for M-types
Equations
- MvPFunctor.M.mk P = MvPFunctor.M.corec P fun (i : ↑P (α ::: P.M α)) => MvFunctor.map (TypeVec.id ::: MvPFunctor.M.dest P) i