Categories of Containers Michael Abbott Thorsten Altenkirch Neil - - PDF document

categories of containers
SMART_READER_LITE
LIVE PREVIEW

Categories of Containers Michael Abbott Thorsten Altenkirch Neil - - PDF document

Categories of Containers Michael Abbott Thorsten Altenkirch Neil Ghani APPSEM-II 26 th 27 th March 2003 1 Strictly Positive Types If X is a type variable, K a constant type and F , G are strictly positive types then so are X . F X . F


slide-1
SLIDE 1

Categories of Containers

Michael Abbott Thorsten Altenkirch Neil Ghani APPSEM-II 26th–27th March 2003

1

slide-2
SLIDE 2

Strictly Positive Types If X is a type variable, K a constant type and F, G are strictly positive types then so are X K F +G F ×G FK µX.F νX.F Each strictly positive type in n variables can be interpreted as a functor Setn → Set Note that neither XX nor 22X are strictly positive.

2

slide-3
SLIDE 3

SP types + polymorphic functions Containers + container morphisms Functors Setn → Set + natural transformations All inclusions are full and faithful and preserve limits and coproducts (but not coequalisers). The category of containers is complete (and cocomplete). Set can be replaced by a locally cartesian closed and locally presentable category.

3

slide-4
SLIDE 4

Example types: pairs, trees, lists. A pair consists of a choice of two elements

  • f X

· · x1 x2 X A binary tree.

  • x3

x1 x2 ∼ =

  • x1

x2 x3 X · · · An element σ ∈ ListX is σ = σ1...σn, ie

  • ...
  • σ1

σ2 σn X 1 2 n n:N σ :{1..n} → X

4

slide-5
SLIDE 5

A “container” is generated by a set

  • f

“shapes” S and for each shape s ∈ S a set

  • f “positions” Ps thus:

(S ⊲ P) ∈ G is (Ps)s∈S . An element of the associated container type, the “extension” of (S ⊲ P), is a choice of shape s ∈ S and a function Ps → X, defining a functor Set → Set thus X → ∑s∈SXP

s . 5

slide-6
SLIDE 6

What is a morphism of containers? Eg:

flatten:TreeX → ListX

tail:ListX → MaybeListX

In general, each shape is mapped to a new shape and each position is mapped back to the position that generates it. Thus a morphism of containers (u, f):(S ⊲ P) → (R ⊲ Q) is u:S → R

  • fs :Qus → Ps
  • s∈S

6

slide-7
SLIDE 7

We can now give a semantics for the the (K, X, +, ×, −K) fragment of strictly positive types X (1 ⊲ 1) K (K ⊲ 0) (S ⊲ P)×(R ⊲ Q) (s:S,r :R ⊲ Ps +Qr) (S ⊲ P)+(R ⊲ Q) (S+R ⊲ P ◦ +Q) (S ⊲ P)K

  • f :SK ⊲ ∑k∈K Pfk
  • For x ∈ S+R define

(P ◦ +Q)x ≡ case x of(s ∈ S : Ps r ∈ R : Qr) . The remaining types Xi, µXi.F, νXi.F need a little more work.

7

slide-8
SLIDE 8

Least Fixed Points Let F ≡ (S ⊲ P,Q) be given with extension F(X,Y) = ∑s∈SXP

s ×Y Qs .

Can we write the fixed point of F as a container µY.F(X,Y) ∼ = ∑s∈S′ XP′

s ?

We know from Dybjer that for each X we can use W-types to compute µY.F(X,Y). However, nested W-types are more problematic.

8

slide-9
SLIDE 9

F(X,Y) = ∑s∈SXP

s ×Y Qs

µY.F(X,Y) ∼ = ∑s∈S′ XP′

s ?

If so we can compute S′: S′ ∼ = µY.F(1,Y) = µY.∑s∈SY Qs ∼ = W(S,Q) . The family of positions can be described as an inductive construction: s ∈ S, f :Qs → S′ ⊢ P′

in(s,f) ∼

= Ps +∑q∈Qs P′

fq .

9

slide-10
SLIDE 10

Lists as Fixed Points

ListX ∼

= µY.1+X ×Y ∼ = ∑n∈NX[n] 1+X ×Y ∼ = X0 ×Y 0 +X1 ×Y 1 (S ⊲ P,Q) ≡ (2 ⊲ (0 ◦ +1),(0 ◦ +1)) S′ = µY.1+Y ∼ = N P′

0 = 0

P′

n+1 = 1+P′ n

This yields, as expected

List = (S′ ⊲ P′) ∼

= ([n])n∈N

10

slide-11
SLIDE 11

Joyal, Foncteurs Analytique et Esp´ eces de Structures Conor McBride, The Derivative of a Regular Type is its Type of One-Hole Contexts Abbott, Altenkirch, Ghani, McBride, Derivatives of Containers

A generic construction ∂ together with a universal one place substitution s:∂F ×X − → F The operator ∂ satisfies the isomorphisms expected of a derivative. ∂(F +G) ∼ = ∂F +∂G ∂X ∼ = 1 ∂K ∼ = 0 ∂(F ×G) ∼ = ∂F ×G+F∂ ×G ∂(F ◦G) ∼ = (∂F ◦G)×∂G Differentiation of least and greatest fixed points also works.

11