131
A Functional Programmer’s Guide to Homotopy Type Theory Dan Licata Wesleyan University 1

A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

A Functional Programmer’s Guideto Homotopy Type Theory

Dan LicataWesleyan University

1

Page 2: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

2

Homotopy type theory

highercategory theory homotopy theory

dependent type theory

Page 3: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4
Page 4: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4
Page 5: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

4

Semantics

highercategory theory homotopy theory

dependent type theory

Awodey,van den Berg,Gambino,Garner,Hofmann,Lumsdaine,Streicher,Voevodsky,Warren 1994-2010

Page 6: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

4

Semantics

highercategory theory homotopy theory

dependent type theory

Awodey,van den Berg,Gambino,Garner,Hofmann,Lumsdaine,Streicher,Voevodsky,Warren 1994-2010

Page 7: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

5

Principles

highercategory theory homotopy theory

dependent type theory

Univalence [Voevodsky, 2006]Higher inductive types [Bauer,Lumsdaine,Shulman,Warren, 2011]

Page 8: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

5

Principles

highercategory theory homotopy theory

dependent type theory

Univalence [Voevodsky, 2006]Higher inductive types [Bauer,Lumsdaine,Shulman,Warren, 2011]

Page 9: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

6

FP as a language for objects of higher homotopy type

Page 10: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

6

FP as a language for objects of higher homotopy type

Page 11: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

Mechanized proofsπ1(S1) = ℤ

πk<n(Sn) = 0

π2(S2) = ℤ

Hopf fibrations

π3(S2) = ℤ

πn(Sn) = ℤ

Freudenthal

K(G,n)

Blakers-Massey

Van Kampen

Covering spaces

Whiteheadfor n-types

Cohomology axioms

[Brunerie,Buchholtz,Cavallo,Finster, Hou,Licata,Lumsdaine,Rilke,Shulman]

T2 = S1 × S1

Mayer-VietorisProjective Spaces

Page 12: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

8

highercategory theory homotopy theory

dependent type theory

Page 13: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

9

What does this all mean in programming terms?

Page 14: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4
Page 15: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

11

Page 16: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

11

Page 17: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

11

Page 18: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

11

In a worldthat’s poweredby violence...

Page 19: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

11

In a worldthat’s poweredby violence...

In a worldwhere owning aradio was strictly

forbidden…

Page 20: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

11

In a worldwhere freedom

is history…

In a worldthat’s poweredby violence...

In a worldwhere owning aradio was strictly

forbidden…

Page 21: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

12

In a world where all functions are monotoneand preserve least upper bounds…

Page 22: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

12

In a world where all functions are monotoneand preserve least upper bounds…

Page 23: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

13

In a world whereall functions are continuous…

λ-terms

CPOs

Page 24: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

13

In a world whereall functions are continuous…

λf.λx.λy.f x yλ-terms

CPOs

Page 25: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

13

In a world whereall functions are continuous…

λf.λx.λy.f x yλ-terms

CPOs function with the propertyof being continuous

Page 26: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

14

In a world whereall functions are continuous…

Y(f) = f(Y(f))λ-terms

CPOs something thatonly exists in that world

Page 27: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

15

In a world where all functionssecretly something… are

Page 28: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

15

In a world where all functionssecretly something… do

Page 29: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

15

In a world where all functionssecretly something… do

get “code for free” / generic programs

Page 30: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

15

In a world where all functionssecretly something… do

get “code for free” / generic programs

can add new principles that depend on them

Page 31: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

16

Homotopy type theory

highercategory theory homotopy theory

dependent type theory

Page 32: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

17

In a world wheretypes are spaces

Page 33: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

17

In a world wheretypes are spaces

each type is a space, with points and paths

Page 34: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

17

programs are points

In a world wheretypes are spaces

each type is a space, with points and paths

Page 35: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

17

programs are points

points can be “literally the same” orconnected by a path

In a world wheretypes are spaces

each type is a space, with points and paths

Page 36: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

18

Many types are discrete (Nat)

0 1 2

3 4 5

Page 37: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

18

Many types are discrete (Nat)

0 1 2

3 4 52+2

Page 38: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

18

Many types are discrete (Nat)

0 1 2

3 4 52+26-2

Page 39: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

19

NM

α

Paths look like equality

Page 40: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

19

Nid

Mid : Path M M

α

Paths look like equalityreflexivity

Page 41: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

19

Nid

Mid : Path M M

α-1 : Path N M

αα-1

Paths look like equalityreflexivity

symmetry

Page 42: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

19

N

P

β

id

Mid : Path M M

α-1 : Path N M

β ◦ α : Path M P

αα-1

Paths look like equalityreflexivity

symmetry

transitivity

Page 43: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

20

N

P

β

M β ◦ α : Path M Pα

But are data

β ◦ α

γ

Page 44: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

20

N

P

β

M β ◦ α : Path M Pα

But are data

γγ : Path M P

β ◦ α

γ

Page 45: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

20

N

P

β

M β ◦ α : Path M Pα

But are data

γγ : Path M P

(β ◦ α) ≠ γβ ◦ α

γ

Page 46: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

20

N

P

β

M β ◦ α : Path M Pα

But are data

γγ : Path M P

(β ◦ α) ≠ γ

¬ PathPath M P (β ◦ α) γ

β ◦ α

γ

Page 47: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

20

N

P

β

M β ◦ α : Path M Pα

But are data

γγ : Path M P

(β ◦ α) ≠ γ

¬ PathPath M P (β ◦ α) γ

β ◦ α

γ

Page 48: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

20

N

P

β

M β ◦ α : Path M Pα

But are data

γγ : Path M P

(β ◦ α) ≠ γ

¬ PathPath M P (β ◦ α) γ

β ◦ α

γ

Page 49: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

21

Functions “secretly” act on paths

f

Page 50: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

21

Functions “secretly” act on paths

f

Page 51: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

21

Path x y →

Path f(x) f(y)

Functions “secretly” act on paths

f

Page 52: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

22

A

B

ua(f,g,…)A B

f

g

Voevodsky’s univalence axiom

bijections induce paths between types

Page 53: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

23

Monad interface (classic)[Godemont,Moggi,Wadler]

Page 54: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

23

Monad interface (classic)[Godemont,Moggi,Wadler]

Page 55: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

24

Applicative interface[McBride,Patterson]

Page 56: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

24

Applicative interface

effects influence value but not structure

[McBride,Patterson]

Page 57: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

24

Applicative interface

effects influence value but not structure

[McBride,Patterson]

Page 58: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

25

Monad interface (new)

Page 59: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

26

Monad interface (new)

Page 60: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

instance Monad Maybe where return a = Some a None >>= k = None (Some a) >>= k = k a sequenceM : ∀ {T A} {Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

Page 61: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

instance Monad Maybe where return a = Some a None >>= k = None (Some a) >>= k = k a sequenceM : ∀ {T A} {Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv) instance App⇒Monad Maybe where return a = Some a None >>= k = None (Some x) >>= k = k x pure a = return a f <*> a = f >>= λf’ # a >>= λ a’ # return (f’ a’) sequenceM : ∀ {T A} {App⇒Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

Page 62: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

pure a = return a f <*> a = f >>= λf’ # a >>= λ a’ # return (f’ a’)

instance Monad Maybe where return a = Some a None >>= k = None (Some a) >>= k = k a sequenceM : ∀ {T A} {Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv) instance App⇒Monad Maybe where return a = Some a None >>= k = None (Some x) >>= k = k x pure a = return a f <*> a = f >>= λf’ # a >>= λ a’ # return (f’ a’) sequenceM : ∀ {T A} {App⇒Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

Page 63: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

instance Monad Maybe where return a = Some a None >>= k = None (Some a) >>= k = k a sequenceM : ∀ {T A} {Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv) instance App⇒Monad Maybe where return a = Some a None >>= k = None (Some x) >>= k = k x pure a = return a f <*> a = f >>= λf’ # a >>= λ a’ # return (f’ a’) sequenceM : ∀ {T A} {App⇒Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

Page 64: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

30

Instance of classic → instance of new

Page 65: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

31

Instance of new → instance of classic

Page 66: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

32

fg

Page 67: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

32

fg

h = f … g

extend interface with an operation that is determined by the others (convenience, efficiency)

fg

Page 68: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

32

fg

h = f … g

extend interface with an operation that is determined by the others (convenience, efficiency)

the (default implementation, forget)-bijectioncan be used to dynamically convert between them

fg

Page 69: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

32

fg

h = f … g

extend interface with an operation that is determined by the others (convenience, efficiency)

the (default implementation, forget)-bijectioncan be used to dynamically convert between them

it’s “obvious” how to apply this in context

fg

Page 70: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

32

fg

h = f … g

extend interface with an operation that is determined by the others (convenience, efficiency)

the (default implementation, forget)-bijectioncan be used to dynamically convert between them

it’s “obvious” how to apply this in context

partially evaluate to modify source code

fg

Page 71: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

33

Paths between types

Monad T

App⇒Monad T

Page 72: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

33

Paths between types

Monad T

App⇒Monad T

Page 73: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

34

Path-related types do not have same elements

A

B

p

Page 74: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

34

Path-related types do not have same elements

A

B

p

but paths between types induce bijections

Page 75: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

34

Path-related types do not have same elements

A

B

coe p : A # Bp

but paths between types induce bijections

Page 76: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

34

Path-related types do not have same elements

A

B

coe p : A # Bp

coe p-1 : B # A

but paths between types induce bijections

Page 77: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

34

Path-related types do not have same elements

A

B

coe p : A # Bp

coe p-1 : B # A

(mutually inverse)

but paths between types induce bijections

Page 78: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

34

Path-related types do not have same elements

A

B

coe p : A # Bp

coe p-1 : B # A

(mutually inverse)

moving along a path might do some work

but paths between types induce bijections

Page 79: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

35

Voevodsky’s univalence axiom

bijections induce paths between types*

Monad T

App⇒Monad T

Nat × String

String × Nat

Page 80: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

36

Coercing along univalence

A Bf

g

Page 81: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

36

A

B

ua(f,g,…)

Coercing along univalence

A Bf

g

Page 82: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

36

A

B

ua(f,g,…)

Coercing along univalence

A Bf

g

coe ua(f,g,…)

Page 83: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

36

A

B

ua(f,g,…)

Coercing along univalence

A Bf

g

coe ua(f,g,…)

coe ua(f,g,…)-1

Page 84: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

36

A

B

ua(f,g,…)

Coercing along univalence

A Bf

g

coe ua(f,g,…)

coe ua(f,g,…)-1

Page 85: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

36

A

B

ua(f,g,…)

Coercing along univalence

A Bf

g

coe ua(f,g,…)

coe ua(f,g,…)-1

Page 86: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

A type B typeA # B type

37

Type constructorsact on points

Page 87: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

α : Path A A’ β : Path B B’α # β : Path (A # B) (A’ # B’)

38

And “secretly” act on paths

Page 88: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

α : Path A A’ β : Path B B’α # β : Path (A # B) (A’ # B’)

38

coe (α # β) (h :A # B) = coe β ◦ h ◦ coe α-1

And “secretly” act on paths

Page 89: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

39

instance Monad Maybe where return a = Some a None >>= k = None (Some a) >>= k = k a sequenceM : ∀ {T A} {Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

Page 90: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

40

ua(d)

Page 91: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

40

C : ((Type # Type) # Type) # Type C Mon = {instance : Mon Maybe, sequenceM : ∀ {T A} {Mon T} # List (T A) # T(List A)}

ua(d)

Page 92: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

40

C : ((Type # Type) # Type) # Type C Mon = {instance : Mon Maybe, sequenceM : ∀ {T A} {Mon T} # List (T A) # T(List A)}

C

C[Monad]

C[App⇒Monad]

ua(d) C[ua(d)]

Page 93: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

40

C : ((Type # Type) # Type) # Type C Mon = {instance : Mon Maybe, sequenceM : ∀ {T A} {Mon T} # List (T A) # T(List A)}

C

C[Monad]

C[App⇒Monad]

ua(d) C[ua(d)]

Page 94: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

40

C : ((Type # Type) # Type) # Type C Mon = {instance : Mon Maybe, sequenceM : ∀ {T A} {Mon T} # List (T A) # T(List A)}

C

C[Monad]

C[App⇒Monad]

ua(d) C[ua(d)]

Page 95: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

41

C[Monad]

C[App⇒Monad]

coe C[ua(d)]

instance Monad Maybe where return a = Some a None >>= k = None (Some a) >>= k = k a sequenceM : ∀ {T A} {Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

Page 96: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

41

C[Monad]

C[App⇒Monad]

coe C[ua(d)]

instance Monad Maybe where return a = Some a None >>= k = None (Some a) >>= k = k a sequenceM : ∀ {T A} {Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

instance App⇒Monad Maybe where return a = Some a None >>= k = None (Some x) >>= k = k x pure a = Some a f <*> a = f >>= λf’ # a >>= λ a’ # return (f’ a’) sequenceM : ∀ {T A} {App⇒Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

Page 97: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

41

C[Monad]

C[App⇒Monad]

coe C[ua(d)]

instance Monad Maybe where return a = Some a None >>= k = None (Some a) >>= k = k a sequenceM : ∀ {T A} {Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

instance App⇒Monad Maybe where return a = Some a None >>= k = None (Some x) >>= k = k x pure a = Some a f <*> a = f >>= λf’ # a >>= λ a’ # return (f’ a’) sequenceM : ∀ {T A} {App⇒Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

coe ua(d)

Page 98: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

42

C[Monad]

C[App⇒Monad]

coe C[ua(d)]

instance Monad Maybe where return a = Some a None >>= k = None (Some a) >>= k = k a sequenceM : ∀ {T A} {Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

instance App⇒Monad Maybe where return a = Some a None >>= k = None (Some x) >>= k = k x pure a = Some a f <*> a = f >>= λf’ # a >>= λ a’ # return (f’ a’) sequenceM : ∀ {T A} {App⇒Monad T} # List (T A) # T(List A) sequenceM [] = return [] sequenceM (x :: xs) = x >>= λ xv # (sequenceM xs) >>= λ xsv # return (xv :: xsv)

coe ua(d)-1

Page 99: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

43

In a world where all functionssecretly something… do

get “code for free” / generic programs

can add new principles that depend on them

Page 100: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

44

in a world where all functions act on paths,… and paths between types induce bijectionsyou can allow bijections to induce paths… and ∴ lift any bijection by a generic program

Univalence

Page 101: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

45

Π,Σ,+,Path,(co)inductives

Which types act on paths? Works for:

Page 102: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

45

intersection types A ∩ B

intensional type analysis case A of B × C ⇒ …

made explicit as × of predicates

can define non-univalentinductive codes for types

Π,Σ,+,Path,(co)inductives

Doesn’t work for:

Which types act on paths? Works for:

Page 103: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

46

Other sources of bijectionsList A ≃ Tree/{assoc,unit} A

List and Tree/{assoc,unit} implementations of ordered collections, if coercion of operations agree:treemap f = fromlist ◦ listmap f ◦ tolist (parametricity for graphs of bijections)

(Σ n:Nat.Vec A n) ≃ List A

Everywhere P xs ≃ (x : A) # x ∊ xs # P x

Lots more in libraries/formalizations

Page 104: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

47

Paths are data

β

α

Page 105: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

47

Paths are data

β

α

Page 106: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

48

Cubical type theories

Bezem,Coquand,Huber; Cohen,Coquand,Huber,Mörtberg; Polonsky; Altenkirch,Kaposi; Isaev; Brunerie,Licata;

Angiuli,Harper,Wilson; Pitts,Orton

Page 107: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

48

Cubical type theories

Bezem,Coquand,Huber; Cohen,Coquand,Huber,Mörtberg; Polonsky; Altenkirch,Kaposi; Isaev; Brunerie,Licata;

Angiuli,Harper,Wilson; Pitts,Orton

Page 108: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

48

Cubical type theories

Bezem,Coquand,Huber; Cohen,Coquand,Huber,Mörtberg; Polonsky; Altenkirch,Kaposi; Isaev; Brunerie,Licata;

Angiuli,Harper,Wilson; Pitts,Orton

Page 109: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

48

Cubical type theories

Bezem,Coquand,Huber; Cohen,Coquand,Huber,Mörtberg; Polonsky; Altenkirch,Kaposi; Isaev; Brunerie,Licata;

Angiuli,Harper,Wilson; Pitts,Orton

Page 110: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

48

Cubical type theories

Bezem,Coquand,Huber; Cohen,Coquand,Huber,Mörtberg; Polonsky; Altenkirch,Kaposi; Isaev; Brunerie,Licata;

Angiuli,Harper,Wilson; Pitts,Orton

Page 111: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

48

Cubical type theories

Bezem,Coquand,Huber; Cohen,Coquand,Huber,Mörtberg; Polonsky; Altenkirch,Kaposi; Isaev; Brunerie,Licata;

Angiuli,Harper,Wilson; Pitts,Orton

Page 112: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

48

Cubical type theories

Bezem,Coquand,Huber; Cohen,Coquand,Huber,Mörtberg; Polonsky; Altenkirch,Kaposi; Isaev; Brunerie,Licata;

Angiuli,Harper,Wilson; Pitts,Orton

Page 113: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

48

Cubical type theories

Bezem,Coquand,Huber; Cohen,Coquand,Huber,Mörtberg; Polonsky; Altenkirch,Kaposi; Isaev; Brunerie,Licata;

Angiuli,Harper,Wilson; Pitts,Orton

Page 114: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

48

Cubical type theories

Bezem,Coquand,Huber; Cohen,Coquand,Huber,Mörtberg; Polonsky; Altenkirch,Kaposi; Isaev; Brunerie,Licata;

Angiuli,Harper,Wilson; Pitts,Orton

Page 115: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

49

Datatypes with paths

Page 116: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

50

Patches as PathsRepos:Type

[Angiuli,Morehouse,L.,Harper]

Page 117: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

50

Patches as PathsRepos:Type

doc[n]

points describe repository contents

[Angiuli,Morehouse,L.,Harper]

Page 118: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

50

Patches as PathsRepos:Type

a↔b@i

doc[n]

points describe repository contents

paths are patches

[Angiuli,Morehouse,L.,Harper]

Page 119: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

50

Patches as PathsRepos:Type

a↔b@i

doc[n]

points describe repository contents

paths are patches

[Angiuli,Morehouse,L.,Harper]

Page 120: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

50

Patches as PathsRepos:Type

a↔b@i

doc[n]

points describe repository contents

paths are patches

doc[n]

doc[n]

doc[n]

doc[n]

[Angiuli,Morehouse,L.,Harper]

Page 121: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

50

Patches as PathsRepos:Type

a↔b@i

doc[n]

points describe repository contents

paths are patches

doc[n]

doc[n]

doc[n]

doc[n]a↔b@i

c↔d@j

c↔d@j

a↔b@i

[Angiuli,Morehouse,L.,Harper]

Page 122: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

50

Patches as PathsRepos:Type

a↔b@i

doc[n]

points describe repository contents

paths are patches

doc[n]

doc[n]

doc[n]

doc[n]a↔b@i

c↔d@j

c↔d@j

a↔b@ii≠jpaths between paths are

equations between patches

[Angiuli,Morehouse,L.,Harper]

Page 123: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

51

space Repos where doc[n:Nat] : Repos a↔b@i : Path doc[n] doc[n] commute : (i<n, j<n, i≠j) # Square (a↔b@i) (c↔d@j) (c↔d@j) (a↔b@i)

Higher inductive type

Page 124: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

52

A

Vec Char n

Page 125: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

52

A

Vec Char n

Page 126: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

52

A

Vec Char n

Page 127: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

52

A

Vec Char n

Page 128: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

53

interp : Repos # Type interp(doc[n]) = Vec Char n interp(a↔b@i) = ua(… actual swap code …) interp(commute) = … proof about above …

Interpreter

Page 129: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

54

highercategory theory homotopy theory

dependent type theory

Page 130: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

55

In a world where all functionssecretly something… are

Page 131: A Functional Programmer’s Guide to Homotopy Type Theory · 2020. 4. 30. · A Functional Programmer’s Guide ... higher category theory homotopy theory dependent type theory. 4

55

In a world where all functionssecretly something… do