Inductive Types for Free Representing Nested Inductive Types using - - PowerPoint PPT Presentation

inductive types for free
SMART_READER_LITE
LIVE PREVIEW

Inductive Types for Free Representing Nested Inductive Types using - - PowerPoint PPT Presentation

Inductive Types for Free Representing Nested Inductive Types using W-types Michael Abbott (U. Leicester) Thorsten Altenkirch (U. Nottingham) Neil Ghani (U. Leicester) Inductive Types for Free p.1/22 Ideology Inductive Types for Free


slide-1
SLIDE 1

Inductive Types for Free

Representing Nested Inductive Types using W-types

Michael Abbott (U. Leicester) Thorsten Altenkirch (U. Nottingham) Neil Ghani (U. Leicester)

Inductive Types for Free – p.1/22

slide-2
SLIDE 2

Ideology

Inductive Types for Free – p.2/22

slide-3
SLIDE 3

Ideology

David Turner: Elementary Strong Functional Programming

Inductive Types for Free – p.2/22

slide-4
SLIDE 4

Ideology

David Turner: Elementary Strong Functional Programming Martin-Löf Type Theory

Inductive Types for Free – p.2/22

slide-5
SLIDE 5

Ideology

David Turner: Elementary Strong Functional Programming Martin-Löf Type Theory Types = sets, programs = total functions.

Inductive Types for Free – p.2/22

slide-6
SLIDE 6

Ideology

David Turner: Elementary Strong Functional Programming Martin-Löf Type Theory Types = sets, programs = total functions. Dependent types to avoid accidental partiality (e.g. hd).

Inductive Types for Free – p.2/22

slide-7
SLIDE 7

Ideology

David Turner: Elementary Strong Functional Programming Martin-Löf Type Theory Types = sets, programs = total functions. Dependent types to avoid accidental partiality (e.g. hd). E.g.: Conor McBride’s Epigram system.

Inductive Types for Free – p.2/22

slide-8
SLIDE 8

Plan of the talk

Inductive and coinductive types. Container types for dummies. Properties of container types. W-types are sufficent for inductive types. Further work and applications Related work

Inductive Types for Free – p.3/22

slide-9
SLIDE 9

Inductive and coinductive types

Widespread in functional programming (e.g. Haskell)

✂✁ ✄ ✁

Lam

☎ ✆ ✝

Int

✞ ✟ ✟

Lam Lam

✞ ✠ ✆ ✡

Lam

Inductive Types for Free – p.4/22

slide-10
SLIDE 10

Inductive and coinductive types

Widespread in functional programming (e.g. Haskell)

✂✁ ✄ ✁

Lam

☎ ✆ ✝

Int

✞ ✟ ✟

Lam Lam

✞ ✠ ✆ ✡

Lam Categorically: Initial algebra of a functor Lam

✂ ✄

Inductive Types for Free – p.4/22

slide-11
SLIDE 11

vs.

  • In a total setting

(terminal coalgebras):

Inductive Types for Free – p.5/22

slide-12
SLIDE 12

vs.

  • In a total setting

(terminal coalgebras):

✂ ✄

finite lists

Inductive Types for Free – p.5/22

slide-13
SLIDE 13

vs.

  • In a total setting

(terminal coalgebras):

✂ ✄

finite lists

✁ ✁ ✂ ✄

potentially infinite lists

Inductive Types for Free – p.5/22

slide-14
SLIDE 14

vs.

  • In a total setting

(terminal coalgebras):

✂ ✄

finite lists

✁ ✁ ✂ ✄

potentially infinite lists

✁ ✁ ✄

infinite lists

Inductive Types for Free – p.5/22

slide-15
SLIDE 15

vs.

  • In a total setting

(terminal coalgebras):

✂ ✄

finite lists

✁ ✁ ✂ ✄

potentially infinite lists

✁ ✁ ✄

infinite lists

Inductive Types for Free – p.5/22

slide-16
SLIDE 16

vs.

  • In a total setting

(terminal coalgebras):

✂ ✄

finite lists

✁ ✁ ✂ ✄

potentially infinite lists

✁ ✁ ✄

infinite lists

  • Inductive Types for Free – p.5/22
slide-17
SLIDE 17

vs.

  • In a total setting

(terminal coalgebras):

✂ ✄

finite lists

✁ ✁ ✂ ✄

potentially infinite lists

✁ ✁ ✄

infinite lists

can be nested

Inductive Types for Free – p.5/22

slide-18
SLIDE 18

vs.

  • In a total setting

(terminal coalgebras):

✂ ✄

finite lists

✁ ✁ ✂ ✄

potentially infinite lists

✁ ✁ ✄

infinite lists

can be nested

✂ ✝ ✄ ✄ ☎
✂ ✄

Inductive Types for Free – p.5/22

slide-19
SLIDE 19

vs.

  • In a total setting

(terminal coalgebras):

✂ ✄

finite lists

✁ ✁ ✂ ✄

potentially infinite lists

✁ ✁ ✄

infinite lists

can be nested

✂ ✝ ✄ ✄ ☎
✂ ✄ ☎
✠ ✁✁ ✂

Inductive Types for Free – p.5/22

slide-20
SLIDE 20

vs.

  • In a total setting

(terminal coalgebras):

✂ ✄

finite lists

✁ ✁ ✂ ✄

potentially infinite lists

✁ ✁ ✄

infinite lists

can be nested

✂ ✝ ✄ ✄ ☎
✂ ✄ ☎
✠ ✁✁ ✂ ✄
✁ ✂ ✂ ✝ ✄ ✆ ✡ ☎ ✁ ✁

Inductive Types for Free – p.5/22

slide-21
SLIDE 21

Axiomatically?

How do we say? All inductive or coinductive datatypes

Inductive Types for Free – p.6/22

slide-22
SLIDE 22

Axiomatically?

How do we say? All inductive or coinductive datatypes Not every parametrized type has an initial algebra (or terminal coalgebra) in set theory, e.g.

Inductive Types for Free – p.6/22

slide-23
SLIDE 23

Axiomatically?

How do we say? All inductive or coinductive datatypes Not every parametrized type has an initial algebra (or terminal coalgebra) in set theory, e.g.

  • Inductive Types for Free – p.6/22
slide-24
SLIDE 24

Axiomatically?

How do we say? All inductive or coinductive datatypes Not every parametrized type has an initial algebra (or terminal coalgebra) in set theory, e.g.

✂ ✁
  • Inductive Types for Free – p.6/22
slide-25
SLIDE 25

Axiomatically?

How do we say? All inductive or coinductive datatypes Not every parametrized type has an initial algebra (or terminal coalgebra) in set theory, e.g.

✂ ✁
  • Strictly positive types, e.g.

Inductive Types for Free – p.6/22

slide-26
SLIDE 26

Axiomatically?

How do we say? All inductive or coinductive datatypes Not every parametrized type has an initial algebra (or terminal coalgebra) in set theory, e.g.

✂ ✁
  • Strictly positive types, e.g.
✂ ✆ ✂
  • rdinal notations

Inductive Types for Free – p.6/22

slide-27
SLIDE 27

Axiomatically?

How do we say? All inductive or coinductive datatypes Not every parametrized type has an initial algebra (or terminal coalgebra) in set theory, e.g.

✂ ✁
  • Strictly positive types, e.g.
✂ ✆ ✂
  • rdinal notations

How do we say? Strictly positive

Inductive Types for Free – p.6/22

slide-28
SLIDE 28

Containers and

  • types

Container types are a syntax-free representation of strictly positive types.

Inductive Types for Free – p.7/22

slide-29
SLIDE 29

Containers and

  • types

Container types are a syntax-free representation of strictly positive types. In an extensive LCCC: W-types (

✁ ✂

) are sufficent to show that container types are closed under

Inductive Types for Free – p.7/22

slide-30
SLIDE 30

Containers and

  • types

Container types are a syntax-free representation of strictly positive types. In an extensive LCCC: W-types (

✁ ✂

) are sufficent to show that container types are closed under

  • (here)

Inductive Types for Free – p.7/22

slide-31
SLIDE 31

Containers and

  • types

Container types are a syntax-free representation of strictly positive types. In an extensive LCCC: W-types (

✁ ✂

) are sufficent to show that container types are closed under

  • (here)

(journal paper, submitted)

Inductive Types for Free – p.7/22

slide-32
SLIDE 32

Containers and

  • types

Container types are a syntax-free representation of strictly positive types. In an extensive LCCC: W-types (

✁ ✂

) are sufficent to show that container types are closed under

  • (here)

(journal paper, submitted) Application: Generic Programming e.g. see our work on derivatives of datatypes

Inductive Types for Free – p.7/22

slide-33
SLIDE 33

Containers and

  • types

Container types are a syntax-free representation of strictly positive types. In an extensive LCCC: W-types (

✁ ✂

) are sufficent to show that container types are closed under

  • (here)

(journal paper, submitted) Application: Generic Programming e.g. see our work on derivatives of datatypes Application: Small trusted cores e.g. for Epigram

Inductive Types for Free – p.7/22

slide-34
SLIDE 34

Containers for dummies

Inductive Types for Free – p.8/22

slide-35
SLIDE 35

Containers for dummies

A container type is given by

Inductive Types for Free – p.8/22

slide-36
SLIDE 36

Containers for dummies

A container type is given by A collection of shapes

  • , e.g.

} , , {

Inductive Types for Free – p.8/22

slide-37
SLIDE 37

Containers for dummies

A container type is given by A collection of shapes

  • , e.g.

} , , {

An assignment of positions to shapes , e.g.

Inductive Types for Free – p.8/22

slide-38
SLIDE 38

Containers for dummies . . .

We can use a container by

Inductive Types for Free – p.9/22

slide-39
SLIDE 39

Containers for dummies . . .

We can use a container by Choosing a shape, e.g.

Inductive Types for Free – p.9/22

slide-40
SLIDE 40

Containers for dummies . . .

We can use a container by Choosing a shape, e.g. Filling the positions with payload (here natural numbers), e.g.

1 4 0

Inductive Types for Free – p.9/22

slide-41
SLIDE 41

Container for scientists

Inductive Types for Free – p.10/22

slide-42
SLIDE 42

Container for scientists

A container type

✁ ✂

is given by

  • a set of shapes

a family of sets of position, e.g.

is a set for any

✁ ✂
  • .

Inductive Types for Free – p.10/22

slide-43
SLIDE 43

Container for scientists

A container type

✁ ✂

is given by

  • a set of shapes

a family of sets of position, e.g.

is a set for any

✁ ✂
  • .

The extension

  • f a container is the

endofunctor

✁ ✂ ✄✆☎ ✄ ✄✆☎ ✄
✁ ☎ ✁ ✂

Inductive Types for Free – p.10/22

slide-44
SLIDE 44

Container for scientists

A container type

✁ ✂

is given by

  • a set of shapes

a family of sets of position, e.g.

is a set for any

✁ ✂
  • .

The extension

  • f a container is the

endofunctor

✁ ✂ ✄✆☎ ✄ ✄✆☎ ✄
✁ ☎ ✁ ✂

Straightforward extension to

  • ary containers
✁ ✂
✁ ✁

.

Inductive Types for Free – p.10/22

slide-45
SLIDE 45

Example: Lists

✠ ✁✁ ✂ ☎
✂ ✄

Inductive Types for Free – p.11/22

slide-46
SLIDE 46

Example: Lists

✠ ✁✁ ✂ ☎
✂ ✄
✆ ✂ ✁ ✁✄✂ ✂ ✆ ✂ ✞ ✂ ☎

Inductive Types for Free – p.11/22

slide-47
SLIDE 47

Example: Lists

✠ ✁✁ ✂ ☎
✂ ✄
✆ ✂ ✁ ✁✄✂ ✂ ✆ ✂ ✞ ✂ ☎
✆ ✂

Inductive Types for Free – p.11/22

slide-48
SLIDE 48

Example: Lists

✠ ✁✁ ✂ ☎
✂ ✄
✆ ✂ ✁ ✁✄✂ ✂ ✆ ✂ ✞ ✂ ☎
✆ ✂ ✄ ☎ ✁✄✂ ✂ ✆ ✂ ✞ ✂ ☎

Inductive Types for Free – p.11/22

slide-49
SLIDE 49

Morphisms of containers

Given containers

  • and
  • a morphism
  • is given by

Inductive Types for Free – p.12/22

slide-50
SLIDE 50

Morphisms of containers

Given containers

  • and
  • a morphism
  • is given by
✁ ✂
✂ ✁

Inductive Types for Free – p.12/22

slide-51
SLIDE 51

Morphisms of containers

Given containers

  • and
  • a morphism
  • is given by
✁ ✂
✂ ✁

its extension is the natural transformation

✂ ☎

Inductive Types for Free – p.12/22

slide-52
SLIDE 52

Representation theorem

Theorem (AAG,FOSSACS 03) The extension functor

is full and faithful.

Inductive Types for Free – p.13/22

slide-53
SLIDE 53

Representation theorem

Theorem (AAG,FOSSACS 03) The extension functor

is full and faithful. Consequence: All polymorphic functions

✂✁ ✂ ✠ ✁
✠ ✁✁ ✂

(i.e. natural transformations) are given by

Inductive Types for Free – p.13/22

slide-54
SLIDE 54

Representation theorem

Theorem (AAG,FOSSACS 03) The extension functor

is full and faithful. Consequence: All polymorphic functions

✂✁ ✂ ✠ ✁
✠ ✁✁ ✂

(i.e. natural transformations) are given by A length transformer

,

Inductive Types for Free – p.13/22

slide-55
SLIDE 55

Representation theorem

Theorem (AAG,FOSSACS 03) The extension functor

is full and faithful. Consequence: All polymorphic functions

✂✁ ✂ ✠ ✁
✠ ✁✁ ✂

(i.e. natural transformations) are given by A length transformer

, A where-did-you-come-from function

  • .

Inductive Types for Free – p.13/22

slide-56
SLIDE 56

Closure properties

Containers are closed under (*) Constant functors, Coproducts ( ) Products (

) Constant exponentation

Composition of functors initial algebras (

  • ) [ICALP 04]

terminal coalgebras (

) [Journal paper]

Inductive Types for Free – p.14/22

slide-57
SLIDE 57

Closure properties

Containers are closed under (*) Constant functors, Coproducts ( ) Products (

) Constant exponentation

Composition of functors initial algebras (

  • ) [ICALP 04]

terminal coalgebras (

) [Journal paper]

(*) In any Martin-Löf category = LCCC (locally cartesian closed category) + W-types.

Inductive Types for Free – p.14/22

slide-58
SLIDE 58

Coproducts of containers

Given containers

☎ ✁ ✂
✁ ☎
  • Inductive Types for Free – p.15/22
slide-59
SLIDE 59

Coproducts of containers

Given containers

☎ ✁ ✂
✁ ☎

Inductive Types for Free – p.15/22

slide-60
SLIDE 60

Coproducts of containers

Given containers

☎ ✁ ✂
✁ ☎
✂ ✁
✁ ✂
✁ ✂ ✝

Inductive Types for Free – p.15/22

slide-61
SLIDE 61

Products of containers

Given containers

☎ ✁ ✂
✁ ☎
  • Inductive Types for Free – p.16/22
slide-62
SLIDE 62

Products of containers

Given containers

☎ ✁ ✂
✁ ☎
☎ ✄

Inductive Types for Free – p.16/22

slide-63
SLIDE 63

Products of containers

Given containers

☎ ✁ ✂
✁ ☎
☎ ✄

Inductive Types for Free – p.16/22

slide-64
SLIDE 64

Initial algebras ( )

Given a 2-ary container

☎ ✁ ✂
✁ ✄ ✁

Inductive Types for Free – p.17/22

slide-65
SLIDE 65

Initial algebras ( )

Given a 2-ary container

☎ ✁ ✂
✁ ✄ ✁
  • Inductive Types for Free – p.17/22
slide-66
SLIDE 66

Initial algebras ( )

Given a 2-ary container

☎ ✁ ✂
✁ ✄ ✁
✁ ✂

Inductive Types for Free – p.17/22

slide-67
SLIDE 67

Initial algebras ( )

Given a 2-ary container

☎ ✁ ✂
✁ ✄ ✁
✁ ✂
✂ ☎
  • Inductive Types for Free – p.17/22
slide-68
SLIDE 68

Initial algebras ( )

Given a 2-ary container

☎ ✁ ✂
✁ ✄ ✁
✁ ✂
✂ ☎
✁ ✁

Inductive Types for Free – p.17/22

slide-69
SLIDE 69

Reply to referee comment

. . . Now, the above is a strictly positive defi nition so should have a least as well as a greatest solution which are not in general isomorphic. Thus the corollary mentioned in the proof of 4.1 would be wrong and as a result the entire argument collapses. I thus fear that the paper must be rejected; . . .

Inductive Types for Free – p.18/22

slide-70
SLIDE 70

Reply to referee comment

. . . Now, the above is a strictly positive defi nition so should have a least as well as a greatest solution which are not in general isomorphic. Thus the corollary mentioned in the proof of 4.1 would be wrong and as a result the entire argument collapses. I thus fear that the paper must be rejected; . . . Reply: Since there are no infinite paths in a finite tree, there is only one solution to this isomorphism, the initial

  • ne.

This is reflected in the proof of proposition 4.1!

Inductive Types for Free – p.18/22

slide-71
SLIDE 71

Constructing the iso

Inductive Types for Free – p.19/22

slide-72
SLIDE 72

Constructing the iso

✂✁ ✄ ☎ ✆✞✝ ✟ ✠ ✡ ☛ ☞ ✌✎✍ ✠ ✏ ☛ ✑ ✒ ✓✕✔ ✏ ☛ ✓ ✔ ✡ ☛ ☞ ✌✎✍ ✠ ✏ ☛ ✑ ✒ ✓ ✔ ✖ ☛

Inductive Types for Free – p.19/22

slide-73
SLIDE 73

Constructing the iso

✂✁ ✄ ☎ ✆✞✝ ✟ ✠ ✡ ☛ ☞ ✌✎✍ ✠ ✏ ☛ ✑ ✒ ✓✕✔ ✏ ☛ ✓ ✔ ✡ ☛ ☞ ✌✎✍ ✠ ✏ ☛ ✑ ✒ ✓ ✔ ✖ ☛ ✡ ☛ ☞ ✌✎✍ ✁ ☛
✂ ✄ ✁ ☎ ✆ ✝ ☎ ✆ ✝ ✟ ✒ ✒

Inductive Types for Free – p.19/22

slide-74
SLIDE 74

Terminal coalgebras [Journal submission]

Inductive Types for Free – p.20/22

slide-75
SLIDE 75

Terminal coalgebras [Journal submission]

The same construction works for the

  • case.

Inductive Types for Free – p.20/22

slide-76
SLIDE 76

Terminal coalgebras [Journal submission]

The same construction works for the

  • case.

Now we have to show that the solution is initial!

Inductive Types for Free – p.20/22

slide-77
SLIDE 77

Terminal coalgebras [Journal submission]

The same construction works for the

  • case.

Now we have to show that the solution is initial! We need

  • types, the dual of
  • types.

Inductive Types for Free – p.20/22

slide-78
SLIDE 78

Terminal coalgebras [Journal submission]

The same construction works for the

  • case.

Now we have to show that the solution is initial! We need

  • types, the dual of
  • types.

However,

  • types can be constructed from
  • types.

Inductive Types for Free – p.20/22

slide-79
SLIDE 79

Terminal coalgebras [Journal submission]

The same construction works for the

  • case.

Now we have to show that the solution is initial! We need

  • types, the dual of
  • types.

However,

  • types can be constructed from
  • types.

See: Containers - Constructing Strictly Positive Types on my publication page.

Inductive Types for Free – p.20/22

slide-80
SLIDE 80

Further work

Quotient containers to model types like bags. First steps, see our MPC paper. Constructing Polymorphic Programs with Quotient Types Dependent containers Work in progress.

Inductive Types for Free – p.21/22

slide-81
SLIDE 81

Related work

Joyal 86 Foncteurs Analytiques et Espèces de Structures Jay 95 A semantics for shape Dybjer 97 Representing inductively defined sets by

wellorderings in Martin-Löf’s type theory

Hoogendijk and de Moor 00 Container Types Categorically Moerdijk and Palmgren 00 Wellfounded Trees in Categories Hasegawa 02 Two applications of analytic functors Gambino and Hyland 03 Wellfounded Trees and Dependent

Polynomial Functors

Inductive Types for Free – p.22/22