Polynomial functors #
This file defines polynomial functors and the W-type construction as a polynomial functor. (For the M-type construction, see pfunctor/M.lean.)
A polynomial functor P
is given by a type A
and a family B
of types over A
. P
maps
any type α
to a new type P α
, which is defined as the sigma type Σ x, P.B x → α
.
An element of P α
is a pair ⟨a, f⟩
, where a
is an element of a type A
and
f : B a → α
. Think of a
as the shape of the object and f
as an index to the relevant
elements of α
.
Instances For
Equations
- PFunctor.instInhabitedPFunctor = { default := { A := default, B := default } }
Equations
Applying P
to a morphism of Type
Equations
- PFunctor.map P f x = match x with | { fst := a, snd := g } => { fst := a, snd := f ∘ g }
Instances For
Equations
- PFunctor.Obj.inhabited P = { default := { fst := default, snd := default } }
Equations
- PFunctor.instFunctorObj P = { map := @PFunctor.map P, mapConst := fun {α β : Type v} => PFunctor.map P ∘ Function.const β }
We prefer PFunctor.map
to Functor.map
because it is universe-polymorphic.
Equations
- (_ : LawfulFunctor ↑P) = (_ : LawfulFunctor ↑P)
re-export existing definition of W-types and adapt it to a packaged definition of polynomial functor
Equations
- PFunctor.W P = WType P.B
Instances For
children of the root of a W tree
Equations
- PFunctor.W.children x = match (motive := (x : PFunctor.W P) → P.B (PFunctor.W.head x) → PFunctor.W P) x with | WType.mk _a f => f
Instances For
destructor for W-types
Equations
- PFunctor.W.dest x = match x with | WType.mk a f => { fst := a, snd := f }
Instances For
constructor for W-types
Equations
- PFunctor.W.mk x = match x with | { fst := a, snd := f } => WType.mk a f
Instances For
Idx
identifies a location inside the application of a pfunctor.
For F : PFunctor
, x : F α
and i : F.Idx
, i
can designate
one part of x
or is invalid, if i.1 ≠ x.1
Equations
- PFunctor.Idx P = ((x : P.A) × P.B x)
Instances For
Equations
- PFunctor.Idx.inhabited P = { default := { fst := default, snd := default } }
x.iget i
takes the component of x
designated by i
if any is or returns
a default value
Equations
- PFunctor.Obj.iget x i = if h : i.fst = x.fst then x.snd (cast (_ : P.B i.fst = P.B x.fst) i.snd) else default
Instances For
functor composition for polynomial functors
Equations
- PFunctor.comp P₂ P₁ = { A := (a₂ : P₂.A) × (P₂.B a₂ → P₁.A), B := fun (a₂a₁ : (a₂ : P₂.A) × (P₂.B a₂ → P₁.A)) => (u : P₂.B a₂a₁.fst) × P₁.B (a₂a₁.snd u) }
Instances For
constructor for composition
Equations
- One or more equations did not get rendered due to their size.
Instances For
destructor for composition
Equations
- One or more equations did not get rendered due to their size.