toward a categorical foundation of functional reactive...

60
Toward a categorical foundation of functional reactive programming David I. Spivak [email protected] Mathematics Department Massachusetts Institute of Technology Presented on 2014/01/23 at Carnegie Mellon University David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 1 / 60

Upload: others

Post on 03-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Toward a categorical foundation of functional reactiveprogramming

David I. Spivak

[email protected]

Mathematics DepartmentMassachusetts Institute of Technology

Presented on 2014/01/23at Carnegie Mellon University

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 1 / 60

Page 2: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Introduction My goal: a visual, formal language for processes

My goal: a visual, formal language for processes

I want to be able to draw pictures like this:

Y

X1

X2

X3

such that, if one fills in each box Xi with a machine, it results in a newmachine for Y .

And I want it all to work as expected.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 2 / 60

Page 3: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Introduction My goal: a visual, formal language for processes

What does all this mean?

But what is a picture like this?

Y

X1

X2

X3

And what kind of machines have this fill-me-in property?

And what expectations should we have about all this?

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 3 / 60

Page 4: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Introduction My goal: a visual, formal language for processes

Plan of this talk

I will show that wiring diagrams (WDs)

Y

X

form a symmetric monoidal category (or SMC), denoted W.

I will show that there is an algebra P : W→ Set of propagators.

I will explain SMCs and their algebras as we go along.

Time permitting, I’ll talk about adding special symbols to thelanguage.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 4 / 60

Page 5: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Introduction Relation to Functional reactive programming

Relation to Functional reactive programming

I began this work to understand the semantics of wiring diagrams.Much of this talk reflects joint work with Dylan Rupel,as well as some preliminary work with Nat Stapleton.

Disclaimers:I’m new to FRP, Incremental Computation, and Haskell arrows.I see them only through the lens of the above category theory, not PL.

I hired a CS grad student to implement these ideas.The student is David Darais, working under Greg Morrisett.Darais told me about the relation to FRP, IC, and Haskell arrows.He had this to offer the audience of this talk:

Haskell arrows are less understood foundationally than ourfavorite object of study: lambda calculus. Wiring diagrams areperhaps the foundation for arrows/FRP that we have all beenwaiting for.

You can see for yourself what you think!

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 5 / 60

Page 6: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Introduction A bit about the notation A → B

A bit about the notation A → B

What does the notation A → B mean in this talk?Type theorists write this to denote what I’d call Hom(A ,B) or BA .When I write A → B, I’m indicating an inhabitant of Hom(A ,B).I might denote this inhabitant f : A → B, like a type theorist,

I might denote it like this: Af−→ B,

or if the inhabitant is clear from context I can write it A → B.

What does A → B → C mean in this talk?Type theorists write this to denote what I’d call Hom(A ,Hom(B ,C)).However, when I write A → B → C, I mean that:

I’ve produced an inhabitant of Hom(A ,B),I’ve produced an inhabitant of Hom(B ,C), andI’m showing you their composite as an inhabitant of Hom(A ,C).

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 6 / 60

Page 7: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Introduction First example: a running total

First example: a running total

Consider the machine+

which takes two integers and reports their sum.Installing it into the following wiring diagram

+

constructs a new machine for the outer box.The constructed machine reports a running total of its inputs.It carries the previous sum on the internal wire as state.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 7 / 60

Page 8: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Introduction Box-manipulation language vs. box-content language

Box-manipulation language vs. box-content language

We want to distinguish between the architecture and the contents.Analogy 1: In databases, we have a schema and an instance.Analogy 2: In a dependent type Σx:X Q(x), think of X as architectureand Q : X → Type as the contents.Today’s wording: syntax and semantics.

A monoidal category W will define the syntax of box-manipulation.A monoidal functor P : W→ Set will model box-contents.

Part of the beauty: there are many monoidal functors W→ Set.In this talk we’ll focus on P, discrete state propagators.One can ask whether continuous propagators also model this Wsyntax.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 8 / 60

Page 9: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams

The picture of W

φ1

φ2

ψ

ψ ◦ (φ1 , φ2)

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 9 / 60

Page 10: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Wires, boxes, wiring diagrams

Wires and boxes

Wires carry a defined set of values.A wire w ∈ Set∗ is a pointed set w = (T , t0), where t0 ∈ T .A finite set of wires is a pair (I, τ), where I = {i1, . . . , in} is a finite set,and τ : I → Set∗ is a function.We write TFS (“typed finite sets”) to denote the collection of (I, τ)’s.

Boxes have input wires and output wires.A box X consists of a pair X := (inp(X), out(X))

inp(X) ∈ TFS is called the set of input wires to X , andout(X) ∈ TFS is called the set of output wires to X .

Another term for box might be interface.

Example: Box X =({a : Z, b : N}, {u : T1, v : Bool, w : T2}

)XZ : a

N : b

T1u :

Boolv :

T2w :

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 10 / 60

Page 11: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Wires, boxes, wiring diagrams

Tensor product of boxes

Given boxes X = (inp(X), out(X)) and Y = (inp(Y), out(Y)),

Xx1

x2

x3

x4

Yy1

y2

y3

we can stack them on top of each other and call that a box

X ⊕ Yx1

x2

y1

x3

x4

y2

y3

Define the tensor product of X and Y , denoted X ⊕ Y , by

X ⊕ Y := (inp(X) + inp(Y), out(X) + out(Y)).

We define the inert box to be � := (∅, ∅). It is a ⊕-unit:

X ⊕ � � X � � ⊕ X .

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 11 / 60

Page 12: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Operad vs. monoidal

Wiring diagrams, operad flavor: Many boxes inside

Operads are many-inside, one-outside.More precisely, morphisms in an operad have many domain objects.For example φ : (X1,X2, . . . ,Xn) −→ Y .

These make for nicer, more intuitive pictures.If desired, one can restrict to the sub-operad of loop-free WDs.

Loop-free being a smaller syntax, it is more easily modeled.For example, spreadsheets (incremental computation?).

φ : (X1,X2) −→ Y

Y

X2

X1

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 12 / 60

Page 13: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Operad vs. monoidal

Wiring diagrams, monoidal flavor: One box inside

Monoidal categories are more like regular old categories.Morphisms in a monoidal category have one domain object.But there’s a tensor operation that serves an operad-like purpose.We can have φ : X1 ⊕ X2 ⊕ · · · ⊕ Xn → Y .

Advantages to using monoidal categories:The mathematics works out cleaner for wiring diagrams.More people know about monoidal categories.

Disadvantage: the pictures can be ugly and unintuitive.Here’s the monoidal version of the picture from the previous slide.

φ : X1 ⊕ X2 −→ Y

Y

X1 ⊕ X2

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 13 / 60

Page 14: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Operad vs. monoidal

Today’s compromise: monoidal maths, operadic pictures

In our case (with loops allowed), these two notions are equivalent.So we’ll go with the pretty option in both cases:

Pretty math: symmetric monoidal categories (SMCs)Pretty pictures: operads.

We’ll write φ : X1 ⊕ X2 → Y and allow ourselves to draw the diagrambelow.

φ : X1 ⊕ X2 −→ Y

Y

X2

X1

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 14 / 60

Page 15: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Morphisms in W

Where are we now?

We’re on our way to defining a symmetric monoidal category W.I’ll tell you the definition of SMC’s soon.For now just bear with me.

An object X ∈ Ob(W) is called a box.Recall a box is a pair X = (inp(X), out(X)) of typed finite sets.The coincidence of the term “object” with OOP is not bad.We are trying to formalize encapsulation.

Boxes can be tensored together by stacking them.

X ⊕ Y =(inp(X) + inp(Y), out(X) + out(Y)

)Morphisms in W are wiring diagrams.

I showed pictures of the monoidal version and the operadic version.Hopefully these pictures make intuitive sense.But I haven’t told you what WDs are mathematically.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 15 / 60

Page 16: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Morphisms in W

Thinking about wiring diagrams

Let X = (inp(X), out(X)) and Y = (inp(Y), out(Y)) be boxes.

What is a wiring diagram?

φ : X → Y

Y

X

Think of φ as an economy, in which every demand needs a supply.The inputs of X are supplied either by inputs of Y or by internal wires.Both the internal wires and the outputs of Y are sourced by X -outputs.A wiring diagram expresses these relationships in terms of functions.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 16 / 60

Page 17: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Morphisms in W

Mathematical formulation of wiring diagrams

Definition

Let X = (inp(X), out(X)) and Y = (inp(Y), out(Y)) be boxes. A wiringdiagram φ : X → Y consists of:

a typed finite set int(φ), called the set of internal wires,

a typed function φin : inp(X) −→ int(φ) + inp(Y), and

a typed function φout : int(φ) + out(Y) −→ out(X).

φ : X → Y

Y

X

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 17 / 60

Page 18: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Morphisms in W

Safe wiring diagrams, Wsafe ⊆ W

Let X = (inp(X), out(X)) and Y = (inp(Y), out(Y)) be boxes.

To make the math fit the pictures, we’ll restrict our attention to certainwiring diagrams.Say that a wiring diagram φ = (int(φ), φin, φout ) is safe if

the internal wires are inputs of X , i.e. int(φ) ⊆ inp(X),the restriction of φin to int(φ), i.e. the composite

int(φ) ⊆ inp(X)φin

−−→ int(φ) + inp(Y),

is the coproduct inclusion, andthe functions φin and φout are surjective.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 18 / 60

Page 19: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Morphisms in W

Unsafe wiring diagrams

Idea: a wiring diagram is unsafe if it has exposed wires.This occurs when φin or φout is not surjective.Recall φin : inp(X)→ int(φ) + inp(Y), andφout : int(φ) + out(Y)→ out(X).

What is the problem with exposed wires?Exposed wires are unsafe in the context of electrical wiring.They’re also unsafe for ones intuition about WDs and propagators.I’ll explain a bit more later.

Unsafe: exposed wires!

Y

X

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 19 / 60

Page 20: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Example of a (safe) wiring diagram (int(φ), φin , φout )

Example of a (safe) wiring diagram (int(φ), φin, φout)

Let X be the box with inp(X) = {a, b} and out(X) = {c, d}.Let Y be the box with inp(Y) = {u} and out(Y) = {v ,w}.Here’s a WD with internal wires int(φ) = {a′}:

φ : X → Y

Y

Xa

a′

b

c

d

u

v

w

Here’s the (surjective) function φin : inp(X) −→ inp(Y) + int(φ):

b 7→ u and a 7→ a′.

Here’s the (surjective) function φout : int(φ) + out(Y) −→ out(X):

a′ 7→ c, v 7→ c, and w 7→ d.David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 20 / 60

Page 21: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Tensor product of wiring diagrams

Tensor product of wiring diagrams

Suppose given two wiring diagrams, φ1 : X1 → Y1 and φ2 : X2 → Y2.Say φ1 = (int(φ1), φin

1 , φout1 ) and φ2 = (int(φ2), φin

2 , φout2 )

To tensor morphisms, we stack them.φ1

φ2

φ1 ⊕ φ2

As with boxes, tensor is achieved by summation across the board:

int(φ1 ⊕ φ2) = int(φ1) + int(φ2),

(φ1 ⊕ φ2)in = φin1 + φin

2 ,

(φ1 ⊕ φ2)out = φout1 + φout

2 ,

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 21 / 60

Page 22: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Composing wiring diagrams

Composing wiring diagrams

We want to be able to plug wiring diagrams into wiring diagrams.

φ1

φ2

ψ ψ ◦ (φ1 ⊕ φ2)

Quiz: what are the internal wires of ψ ◦ (φ1 ⊕ φ2)?

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 22 / 60

Page 23: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams Composing wiring diagrams

Composing wiring diagrams, Xφ−→ Y

ψ−→ Z

Recall that each wiring diagram, say φ, consists ofa typed finite set of internal wires int(φ),a typed function φin : inp(X)→ int(φ) + inp(Y), anda typed function φout : int(φ) + out(Y)→ out(X).

The internal wires of ψ ◦ φ are int(ψ ◦ φ) := int(φ) + int(ψ).

The function (ψ ◦ φ)in : inp(X)→ int(ψ ◦ φ) + inp(Z) is given by

inp(X)φin

−−→ int(φ) + inp(Y)int(φ)+ψin

−−−−−−−−−→ int(φ) + int(ψ) + inp(Z).

The function (ψ ◦ φ)out : int(ψ ◦ φ) + out(Z)→ out(X) is given by

int(φ) + int(ψ) + out(Z)int(φ)+ψout

−−−−−−−−−−→ int(φ) + out(Y)φout

−−−→ out(X).

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 23 / 60

Page 24: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams W is a symmetric monoidal category

W is a symmetric monoidal category

Let’s recap what we know about W.First of all, W is a category:

We defined an object of W to be a box (a pair of typed finite sets).We defined a morphism φ : X → Y in W to be a wiring diagram,

(int(φ), φin, φout ).

On the last slide we showed the composition formula for ψ ◦ φ.The identity (having int(idX ) = ∅) is straightforward.Proving the associativity law is straightforward too.So we indeed have a category.

Add a tensor product to that, and we have an SMC.The tensor product needs to satisfy some laws:

For example, we need X ⊕ Y � Y ⊕ X .Another example: � ⊕ X � X � X ⊕ �.But these are all straightforward, because we’re just working with finitesets and their sums.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 24 / 60

Page 25: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams What is a symmetric monoidal category

What is a symmetric monoidal category

A symmetric monoidal category consists ofa categoryM,a functor ⊗ : M×M→M, called the tensor,an object I ∈ Ob(M) called the unit,as well as various coherence isomorphisms and commutativediagrams that ensure that everything works as expected, e.g.

X ⊗ I � X � IX ,(X ⊗ Y) ⊗ Z � X ⊗ (Y ⊗ Z), etc.

Your favorite: Type with Cartesian ×, and unit type 1.

Another: Set with disjoint union +, and unit set ∅.

Another: VectR with tensor product ⊗, and unit vector space R.

Another: W with stacking tensor ⊕, and inert box �.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 25 / 60

Page 26: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The monoidal category W of wiring diagrams What is a symmetric monoidal category

Quick aside: how is ⊗ different than ×?

Some people want to know how ⊗ is different than Cartesian product.Note that (Set,×, 1) is an SMC, so we must be saying SMCs aremore general, i.e. that × is more constrained than arbitrary ⊗.

The additional constraint on × is that you can project,

A ←− A × B −→ B .

Note that (Set,+, 0) is an SMC, but there is no canonical mapA + B → B.Objection: “But in this case it’s flipped. Are monoidal categories just...?”

Consider the SMC category Wsafe of boxes and wiring diagrams.We neither have maps X ⊕ Y → X nor X → X ⊕ Y in general.Example X = � and Y = ({y : N}, ∅).

None possible None possible

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 26 / 60

Page 27: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators The basic idea behind W-algebras

So... what to plug into these boxes?

We have this syntax of boxes; what are we going to do with it?“Let’s put stuff into them!”“What can we put into them?”“Whatever we want, as long as we understand stacking and wiring.”

A W-algebra is a lax monoidal functor

F : W→ Set.

To choose a W-algebra F is to choose semantics for the box syntax.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 27 / 60

Page 28: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators The basic idea behind W-algebras

What is a lax monoidal functor F : W→ Set?

Suppose we want to choose semantics F for this box syntax.We get to choose what we allow ourselves to put into the boxes.

For a box X ∈ Ob(W) we get to choose a set F(X).Once we’ve done so, we’ll call f ∈ F(X) an F-fill for box X .

We get to say how to stack F-fills.Given boxes X ,Y and F-fills f ∈ F(X) and g ∈ F(Y),we need to give an F-fill for their tensor, σ(f , g) ∈ F(X ⊕ Y).

We get to say how a wiring diagram φ : X → Y sends fills for X to fillsfor Y .Once we do that, we will have specified:

a function Ob(F) : Ob(W)→ Ob(Set),a function σX ,Y : F(X) × F(Y)→ F(X ⊕ Y), anda function HomF : HomW(X ,Y)→ HomSet(F(X),F(Y)).

For our choices to constitute a W-algebra, various laws must hold.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 28 / 60

Page 29: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators The basic idea behind W-algebras

Some stupid W-algebras

LetM = (M, ?, e) be any commutative monoid.For example the natural numbers, with addition, (N,+, 0),or the integers, with multiplication, (Z, ∗, 1),or the subsets of some set, with union, (P({0, 1, . . . , 9}),∪, ∅).

Then there is an algebra F : W→ Set that assignsF(X) := M,σ := ? : M ×M → M, andHomF (φ) := idM .

For example, with M = (N,+, 0), we have

15

5

6

4

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 29 / 60

Page 30: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators The basic idea behind W-algebras

More interesting algebras W→ Set

The previous algebras didn’t take advantage of the wiring structure.

We will focus on propagators, taking input-streams to output-streams.Variations include:

asking the propagators to be continuous or differentiable.continuous-time machines, etc.

In each case, just say what to put into boxes and how stacking andwiring are to work.

Resulting fill?

fill1

fill2

fill3

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 30 / 60

Page 31: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators The basic idea behind W-algebras

A questionable algebra

One idea might be to put into each box the set of functions of thespecified type.

That is, suppose X is the box below.Define F (X) = Hom(Z × N,T1 × Bool × T2), the set of functions.

XZN

Bool

But then how do wiring diagrams operate on functions?Recall the running total.

It is made out of a pure function, but the result is not functional.The same input in two successive moments returns different outputs.

+1, 1, 1, 1 1, 2, 3, 4

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 31 / 60

Page 32: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators State propagators

State propagators

Definition

Let A and B be sets. An (A ,B)-propagator consists of

1. a set S, called the state-set,

2. a function f : S × A → S × B, called the propagation function.

An (A ,B)-propagator is called initialized if we have chosen

3. an element s0 ∈ S, called the initial state.

We call a propagator (S, f) simple if its state-set has one element, |S | = 1.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 32 / 60

Page 33: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators State propagators

Aside: Initialized propagators act on lists

Let (S, s0, f) be an initialized (A ,B)-propagator, where s0 ∈ S.

For convenience, swap the propagation function’s outputs:

f : S × A −→ B × S.

For n ∈ N, we define fn : An → Bn × S, as follows:define f0 = s0, the initial state, anddefine fn+1 : An+1 −→ Bn+1 × S to be the composite

An × Afn×A−−−−→ Bn × S × A

Bn×f−−−−→ Bn × B × S

Project each fn : An → Bn × S and then sum the results to obtain

LP(S, s0, f) : List(A) −→ List(B),

called the list propagator associated to (S, s0, f).

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 33 / 60

Page 34: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators State propagators

Fill box X with the set of X -propagators

Quick aside on dependent products: notation and contravariance.Given a typed finite set (I, τ) we denote the dependent product by

(I, τ) :=∏i∈I

τ(i).

This is contravariant: given a typed function p : (I, τ)→ (I′, τ′) we get

p : (I′, τ′)→ (I, τ).

Recall that a box X = (inp(X), out(X)) is a pair of typed finite sets.For example, if inp(X) = {a : Z, b : Bool}, then inp(X) = Z × Bool.Define X := (inp(X), out(X)).

So an X -propagator includes a state-set S and a propagation function

f : S × inp(X) −→ S × out(X).

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 34 / 60

Page 35: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators P : W→ Set on objects

P : W→ Set on objects

On boxes X ∈ Ob(W), define P(X) to be the set of X -propagators,For example, let X = ({a : N, b : N}, {u : N, v : Bool,w : N}),

N : a

N : b

Nu :

Boolv :

Nw :

Choosing an initialized X -propagator means:choosing a state set S, an initial state s0 ∈ S, and a function,

f : S × (N × N)→ S × (N × Bool × N).

For example, let’s choose S = N × N, with s0 = (0, 0), and

f((s1, s2), a, b) = ((s1 + a, s2 + b), (s1, s1?= s2, s2)).

This returns running totals of a and b, as well as whether they’re equal.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 35 / 60

Page 36: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators Stacking propagators

Stacking propagators

Recall an X -propagator consists of a set S and a function

f : S × inp(X)→ S × out(X).

For any two boxes X ,Y ∈ Ob(W), we need a stacking function

σX ,Y : P(X) × P(Y)→ P(X ⊕ Y).

Given an X -propagator (S, f) and a Y -propagator (T , g), we need aX ⊕ Y -propagator.We use σX ,Y ((S, f), (T , g)) := (S × T , f × g).

(S, f)

(T , g)

σX ,Y

(S × T , f × g)

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 36 / 60

Page 37: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators Wiring propagators

Wiring propagators

We’ve decided how P : W→ Set works on boxes X ∈ Ob(W);

We’ve decided how P works with stacking.

Now we need to decide how P works with wiring diagrams.

Resulting fill?

fill1

fill2

fill3

Afterwards we need to check that the composition formula holds.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 37 / 60

Page 38: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators Wiring propagators

P(φ) : P(X) −→ P(Y)

We begin with boxes X and Y , and a wiring diagram φ : X → Y .Recall that each wiring diagram, say φ, consists of

a typed finite set of internal wires int(φ),a typed function φin : inp(X)→ int(φ) + inp(Y), anda typed function φout : int(φ) + out(Y)→ out(X).

Recall the contravariance of dependent products, e.g.

φin : int(φ) × inp(Y) −→ inp(X).

Suppose given an X -propagator (S, f) ∈ P(X), where

f : S × inp(X) −→ S × out(X).

We need to define a Y -propagator (T , g) = P(φ)(S, f) ∈ P(Y).For the new state-set, use the product, T := S × int(φ).For the new propagation function, use the composite,

S × int(φ) × inp(Y)S×φin

−−−−→ S × inp(X)f−−−→ S × out(X)

S×φout

−−−−−→ S × int(φ) × out(Y).

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 38 / 60

Page 39: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators Wiring propagators

Example wiring diagram φ : X → Y

Let all wires carry the pointed type (N, 0).Note that there is one internal wire, so int(φ) = N.

φ : X → Y

Y

X

Consider the X -propagator ({∗},+), where +: N × N→ N is sum.Then P(φ)({∗},+) = (N, f) has propagation function given by

f(s, y) = (s + y, s + y)

As a list propagator, it reports the running total as advertised,(y1, . . . , yn) 7→

∑ni=1 yi .

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 39 / 60

Page 40: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators Quick aside about safe WDs

Quick aside about safe WDs

We’ve only been drawing safe WDs.the internal wires are inputs of X , i.e. int(φ) ⊆ inp(X),the restriction of φin to int(φ), i.e. the composite

int(φ) ⊆ inp(X)φin

−−→ int(φ) + inp(Y),

is the coproduct inclusion, andthe functions φin and φout are surjective.

Safe WDs form a symmetric monoidal subcategory of all WDs.

Wsafe ⊆ W.

When WDs are not safe, it becomes harder to interpret int(φ).

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 40 / 60

Page 41: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators Quick aside about safe WDs

An example of non-safe WDs

The issue: there are multiple ways to interpret this wiring diagram:φ : X → Y

Since φout : int(φ) + out(Y)→ out(X) need not be surjective,the size of int(φ) could be 0 or 1, or anything for that matter!Our choice influences the state-set of new propagators.Weird things happen when considering compositions such as:

Xφ−→ Y

ψ−→ Z X

ψ◦φ−−−→ Z

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 41 / 60

Page 42: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators Quick aside about safe WDs

Aside: another example of scary stuff we prevent

Early on, we thought a wiring diagram φ : X → Y should be:an assignment of demand wires to supply wires. That is,a typed function φ : inp(X) + out(Y) −→ inp(Y) + out(X).In particular, a wire could connect out(Y) directly to inp(Y).

But this has problems, especially if we want to allow loops.

?

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 42 / 60

Page 43: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators Checking P on the composition Xφ−→ Y

ψ−→ Z

Checking P on the composition Xφ−→ Y

ψ−→ Z

We have defined P : W→ Set on objects, morphisms, and stacking.

We must check that it works well with composition.

The computation is very straightforward:

S × int(φ) × int(ψ) × inp(Z)S×int(φ)×ψin

//

P(ψ◦φ)(f)

��

S × int(φ) × inp(Y)S×φin

//

P(φ)(f)

��

S × inp(X)

f

��S × int(φ) × int(ψ) × out(Z) S × int(φ) × out(Y)

S×int(φ)×ψoutoo S × out(X)

S×φoutoo

I show you this not because it’s hard, but because it’s easy.We worked hard to make this as simple as possible.Our goal was to have something people would want to use!

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 43 / 60

Page 44: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

The W-algebra of propagators Checking P on the composition Xφ−→ Y

ψ−→ Z

The subalgebra generated by NANDs?

Each transistor on a chip acts as a NAND gate, a simple propagator.

NAND

NOT

NAND

From here we can get NOT gates, then AND gates, and all logic gates.Then n-bit adders, multiplication circuits, etc.

Consider the box T := ({a, b : Bool}, {c : Bool}) ∈ Ob(W).Begin with the free algebra on T , denoted Fr(T) : W→ Set.It is the algebra that sends X to

∑n∈N HomW(T⊕n,X).

Now, there’s a unique map Fr(T)→ P, sending T 7→ NAND.Its image defines the algebra of propagators generated by NAND.

Question: How does it compare to the computable functions?

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 44 / 60

Page 45: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Changing the state-set Morphisms of propagators

Morphisms of propagators

Let A and B be pointed sets.

Suppose we have two (A ,B)-propagators, (S, f) and (T , g).A morphism of propagators from (S, f) to (T , g) consists of:

a function ρ : S → T ,such that the following diagram commutes:

S × A f //

ρ×A��

S × B

ρ×B��

T × A g// T × B

If we’re working with initialized propagators, we require ρ(s0) = t0.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 45 / 60

Page 46: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Changing the state-set Morphisms of propagators

Connected propagators act the same on lists

Let (S, s0, f) be an initialized (A ,B)-propagator.Recall: for each n ∈ N, it induces a function An → Bn, andtheir sum is a function LP(S, s0, f) : List(A)→ List(B).

Suppose given a morphism ρ : (S, s0, f)→ (T , t0, g) of propagators.

In this case it is easy to show that LP(S, s0, f) = LP(T , t0, g).So if two propagators are connected, they act the same on lists.

We write (S, s0, f) ∼ (T , t0, g) if they are connected by a zigzag.(Aside: zigzags are chains like this, P0 ← P1 → P2 ← · · · → Pn.)The relation ∼ is an equivalence relation on X -propagators.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 46 / 60

Page 47: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Changing the state-set Morphisms of propagators

List(A) can always serve as state-set

Let (S, s0, f) be an initialized (A ,B)-propagator.For each n ∈ N, it induces a function fn : An → S × Bn.For convenience, we give names to its first and last projections,

σn : An → S and ωn+1 : An+1 → B .

We’ll find an equivalent propagator with state-set List(A).Let T = List(A) and let t0 = [ ] be the empty list.We need a propagation function f̂ : T × A −→ T × B.It’s sufficient to provide f̂n : An × A −→ An+1 × B for every n ∈ N.Use the top row in the diagram below.

An × A

σn×A��

An+1 (An+1,ωn+1) // An+1 × B

σn+1×B��

S × Af

// S × B

The rest of the diagram shows the morphism (T , t0, f̂)→ (S, s0, f).

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 47 / 60

Page 48: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Changing the state-set State reduction

State reduction

For any (A ,B)-propagator (S, s0, f) we found a morphism

ρ : (List(A), [ ], f̂) −→ (S, s0, f).

In fact ρ is unique.The image of ρ is some (S′, s0, f) having a subset of states S′ ⊆ S.S′ is the set of reachable states, those that obtain on some list of input.

We can also quotient by an equivalence relation on states.Declare two states equivalent if they act the same on any input list.We have LP(S,−, f) : S −→ List(B)List(A).Let S̃ be its image, so we have q : S � S̃ ⊆ List(B)List(A).So S̃ is the quotient of S by the equivalence relation.It is easy to show that S̃ is the state-set for an equivalent propagator.

S × A f //

q×A��

S × B

q×B��

S̃ × Af̃// S̃ × B

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 48 / 60

Page 49: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Changing the state-set Algorithmic state reduction

Algorithmic state reduction

Given an (A ,B)-propagator, we want the smallest equivalent one.If (S, s0, f) is such that every state is reachable, use (S̃, s0, f̃).In this case, and if A and S are finite, Hopcroft’s algorithm finds thesmallest equivalent propagator (S̃, s0, f̃) in O(|S ||A |log|S |) time.

If some states are not reachable, use(˜List(A), [ ],

˜̂f) .Call this the minimal reduction of (S, s0, f).

It is a normal form for propagators.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 49 / 60

Page 50: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Changing the state-set State reduction and wiring diagrams

State reduction and wiring diagrams

Back to the main theme, we had P : W→ Set.But in fact it can be extended to a monoidal functor P : W→ Cat.

For each X ∈ Ob(W) we now have a category P(X) of propagators.For stacking boxes, there’s a functor P(X) × P(Y)→ P(X ⊕ Y).For each WD φ : X → Y there’s a functor P(φ) : P(X)→ P(Y).And these all work together as required.

This means that reducing commutes with wiring.Given a morphism φ : X → Y and a propagator P ∈ P(X),you can reduce P � P′ then apply P(φ),and the result is a reduction, P(φ)(P)� P(φ)(P′).

Note that this does not say much about minimal reduction.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 50 / 60

Page 51: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Changing the state-set State reduction and wiring diagrams

Minimal reduction for wiring diagrams?

Suppose given a wiring diagram φ : X1 ⊕ X2 −→ Y .

φ : X1 ⊕ X2 → Y

Y

X1

X2

And suppose given propagators P1 ∈ P(X1) and P2 ∈ P(X2).You can find minimal reductions of each, but it’s a waste of time.

If P1 only spits out one value, it effectively reduces P2’s input set.

Question: find an efficient algorithm to minimize P(φ)(P1,P2)?Can you take advantage of the knowledge that it has this form?Perhaps use machine learning to “atrophy” unused expressivity in thewires?

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 51 / 60

Page 52: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Customizing the language

How’s the time?

Shall we change gears a bit, or skip to the end?

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 52 / 60

Page 53: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Customizing the language Wiring diagrams as a visual language

Wiring diagrams as a visual language

One major feature of wiring diagrams is to engage the human visualsystem.

Operadic pictures are a visual language for building instructions.The category W purely syntactic.

We can build predefined functions into W.For example, delay propagators might be denoted by nodes −•−.

Y

X

Or propagators that bundle four wires into a bus might be denoted by4 .

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 53 / 60

Page 54: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Customizing the language Wiring diagrams as a visual language

Aside: timing in a wiring diagram

The formulas are written above; here we interpret them in terms oftiming.

Wires move data instantaneously.Each propagator takes one “clock-cycle” to process data.

Consider a box X with one input wire and one output wire,inp(X) = {T } = out(X) of the same type, T .

XT T

We define the delay propagator of type T to be the simple propagatorwith propagation function idT : T → T .

delayed +

+

id

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 54 / 60

Page 55: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Customizing the language Baking in special propagators

Baking in special propagators

What does it mean to bake the delay node −•−, etc., into W?

We want the following to count as a wiring diagram φ : X → Y .

Y

X

That is, we name special boxes for which we have choseninterpretations.

What’s the math?

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 55 / 60

Page 56: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Customizing the language Baking in special propagators

The math for baking in special symbols, part 1

We need to choose special symbols in W and propagators for them.Fix a SMC, S, objects of which are called special symbols.Fix a strict monoidal functor ι : S → W.For each symbol s ∈ Ob(S) choose an element ms ∈ P(ι(s)).

S

!

��

ι // W

P

��•

{1}//

mt

Set

Now define a new SMC, denoted W[S] as follows:It has the same objects as W, but morphisms are defined as:

HomW[S](X ,Y) =∑

s∈Ob(S)

HomW(X ⊕ ι(s),Y).

Given X ⊕ ι(s)→ Y and Y ⊕ ι(t)→ Z ,we can compose to X ⊕ ι(s ⊕ t)→ Z , because ι is strict.Stacking ⊕ in W[S] is also achieved by the strictness of ι.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 56 / 60

Page 57: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Customizing the language Baking in special propagators

The math for baking in special symbols, part 2

We have constructed a SMC denoted W[S] out of our setup,

S

!

��

ι // W

P

��•

{1}//

mt

Set

Note we haven’t used m yet, we’ve only used ι up to now.

We need an algebra P[S] : W[S]→ Set.Have it act the same on boxes as P does: P[S](X) := P(X).A morphism φ : X → Y in W[S] is a morphism φ : X ⊕ ι(s)→ Y in W.We need to assign a function P[S](φ) : P(X)→ P(Y).Use the following composite:

P(X) � P(X) × {1}P(X)×m−−−−−−→ P(X) × P(ι(s))

�−→ P(X ⊕ ι(s))

P(φ)−−−−−−→ P(Y).

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 57 / 60

Page 58: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Conclusion Work to be done (please feel free to help!)

Work to be done (please feel free to help!)

I’d like wiring diagrams to be implemented.As mentioned in the introduction, David Darais plans to do so.But I encourage others to do so as well!I’d like an open source WD-programming language, based in NANDs.Does the operadic enclosure operation adequately handle abstraction?

I’d like an operadic model of reinforcement learning.Each box could represent a population of learning agents.Suppose given an operadic wiring diagram φ : (X1, . . . ,Xn)→ Y .Can φ distribute global rewards among the Xi in such a way that:

if each Xi optimizes its behavior according to this sub-reward,the result is that Y has optimized according to the global reward?

Similar vein: operadic verification and validation?

Y

X1

X2

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 58 / 60

Page 59: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Conclusion Summary

Summary

We can draw pictures like this:

Y

X1

X2

X3

Such a picture represents a morphism φ : X1 ⊕ X2 ⊕ X3 −→ Y in asymmetric monoidal category called W.We can fill each interior box of φ with a machine, and thus derive amachine for the exterior box.We can abstract away the details of any part by enclosing it.The requisite formulas are straightforward and written out here in full.

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 59 / 60

Page 60: Toward a categorical foundation of functional reactive ...math.mit.edu/~dspivak/informatics/talks/CMU2014-01-23.pdf · Introduction Relation to Functional reactive programming Relation

Conclusion Summary

Thanks!

Thanks for inviting me!

Fibonacci

+

All wires carry (N, 1).

. . . , 8, 5, 3, 2, 1, 11, 1, 2, 3, 5, 8, . . .

David I. Spivak (MIT) A categorical foundation of FRP Presented on 2014/01/23 60 / 60