An Introduction to Type Theory Part 3 Tallinn, September 2003 with - - PowerPoint PPT Presentation

an introduction to type theory
SMART_READER_LITE
LIVE PREVIEW

An Introduction to Type Theory Part 3 Tallinn, September 2003 with - - PowerPoint PPT Presentation

An Introduction to Type Theory Part 3 Tallinn, September 2003 with cartoons by Conor McBride http://www.cs.nott.ac.uk/txa/tallinn/ Thorsten Altenkirch University of Nottingham An Introduction to Type Theory p.1/32 The established


slide-1
SLIDE 1

An Introduction to Type Theory

Part 3

Tallinn, September 2003 with cartoons by Conor McBride http://www.cs.nott.ac.uk/˜txa/tallinn/

Thorsten Altenkirch University of Nottingham

An Introduction to Type Theory – p.1/32

slide-2
SLIDE 2

The established social order

An Introduction to Type Theory – p.2/32

slide-3
SLIDE 3

The established social order

terms

An Introduction to Type Theory – p.2/32

slide-4
SLIDE 4

The established social order

terms types

An Introduction to Type Theory – p.2/32

slide-5
SLIDE 5

The established social order

terms types do all the work

An Introduction to Type Theory – p.2/32

slide-6
SLIDE 6

The established social order

terms types do all the work are never around when there is work to be done

An Introduction to Type Theory – p.2/32

slide-7
SLIDE 7

The established social order

terms types do all the work are never around when there is work to be done engage in criminal activity

An Introduction to Type Theory – p.2/32

slide-8
SLIDE 8

The established social order

terms types do all the work are never around when there is work to be done engage in criminal activity commit no crime

An Introduction to Type Theory – p.2/32

slide-9
SLIDE 9

The established social order

terms types do all the work are never around when there is work to be done engage in criminal activity commit no crime can be stopped and searched

An Introduction to Type Theory – p.2/32

slide-10
SLIDE 10

The established social order

terms types do all the work are never around when there is work to be done engage in criminal activity commit no crime can be stopped and searched cannot be investigated.

An Introduction to Type Theory – p.2/32

slide-11
SLIDE 11

The established social order

terms types do all the work are never around when there is work to be done engage in criminal activity commit no crime can be stopped and searched cannot be investigated. belong to and are hold in check by types

An Introduction to Type Theory – p.2/32

slide-12
SLIDE 12

The established social order

terms types do all the work are never around when there is work to be done engage in criminal activity commit no crime can be stopped and searched cannot be investigated. belong to and are hold in check by types

An Introduction to Type Theory – p.2/32

slide-13
SLIDE 13

The established social order

terms types do all the work are never around when there is work to be done engage in criminal activity commit no crime can be stopped and searched cannot be investigated. belong to and are hold in check by types

An Introduction to Type Theory – p.2/32

slide-14
SLIDE 14

Ersatz dependent types

An Introduction to Type Theory – p.3/32

slide-15
SLIDE 15

Ersatz dependent types

In modern type systems types have to do some work

An Introduction to Type Theory – p.3/32

slide-16
SLIDE 16

Ersatz dependent types

In modern type systems types have to do some work Polymorphic types can be use to represent square matrices

✂✁ ✄✆☎ ✝✟✞ ✠ ✡
✄✆☎ ✝✟✞ ☛ ☞ ✝ ✌ ✠ ✂✁ ✄✆☎ ✝✟✞ ☛✎✍ ✠ ✡ ✏✂✑ ☎ ✒ ✓ ✍ ✓ ✍ ✠ ✔ ✔✕ ✖✘✗ ✙ ✙ ✓ ✚ ✒ ✛ ✜ ✍ ✔ ✠ ☞ ✝ ✌ ✠ ✡ ☞ ✝ ✌ ✚ ✒ ✛ ✜ ✍ ✠ ✡ ✚ ✒ ✛ ✜ ✠ ✓ ✍ ✠ ✔

An Introduction to Type Theory – p.3/32

slide-17
SLIDE 17

Ersatz dependent types

In modern type systems types have to do some work Polymorphic types can be use to represent square matrices

✂✁ ✄✆☎ ✝✟✞ ✠ ✡
✄✆☎ ✝✟✞ ☛ ☞ ✝ ✌ ✠ ✂✁ ✄✆☎ ✝✟✞ ☛✎✍ ✠ ✡ ✏✂✑ ☎ ✒ ✓ ✍ ✓ ✍ ✠ ✔ ✔✕ ✖✘✗ ✙ ✙ ✓ ✚ ✒ ✛ ✜ ✍ ✔ ✠ ☞ ✝ ✌ ✠ ✡ ☞ ✝ ✌ ✚ ✒ ✛ ✜ ✍ ✠ ✡ ✚ ✒ ✛ ✜ ✠ ✓ ✍ ✠ ✔

Conor showed in Faking it how to use the logic programming of Haskell’s class system to simu- late some usages of dependent types.

An Introduction to Type Theory – p.3/32

slide-18
SLIDE 18

Ersatz dependent types

In modern type systems types have to do some work Polymorphic types can be use to represent square matrices

✂✁ ✄✆☎ ✝✟✞ ✠ ✡
✄✆☎ ✝✟✞ ☛ ☞ ✝ ✌ ✠ ✂✁ ✄✆☎ ✝✟✞ ☛✎✍ ✠ ✡ ✏✂✑ ☎ ✒ ✓ ✍ ✓ ✍ ✠ ✔ ✔✕ ✖✘✗ ✙ ✙ ✓ ✚ ✒ ✛ ✜ ✍ ✔ ✠ ☞ ✝ ✌ ✠ ✡ ☞ ✝ ✌ ✚ ✒ ✛ ✜ ✍ ✠ ✡ ✚ ✒ ✛ ✜ ✠ ✓ ✍ ✠ ✔

Conor showed in Faking it how to use the logic programming of Haskell’s class system to simu- late some usages of dependent types.

An Introduction to Type Theory – p.3/32

slide-19
SLIDE 19

Breaking the old social order

An Introduction to Type Theory – p.4/32

slide-20
SLIDE 20

Breaking the old social order

Data is validated wrt other data

An Introduction to Type Theory – p.4/32

slide-21
SLIDE 21

Breaking the old social order

Data is validated wrt other data If types are to capture the validity of data, we must let them depend on terms.

An Introduction to Type Theory – p.4/32

slide-22
SLIDE 22

Breaking the old social order

Data is validated wrt other data If types are to capture the validity of data, we must let them depend on terms.

An Introduction to Type Theory – p.4/32

slide-23
SLIDE 23

Breaking the old social order

Data is validated wrt other data If types are to capture the validity of data, we must let them depend on terms.

An Introduction to Type Theory – p.4/32

slide-24
SLIDE 24

Breaking the old social order

Data is validated wrt other data If types are to capture the validity of data, we must let them depend on terms.

An Introduction to Type Theory – p.4/32

slide-25
SLIDE 25

Overview

An Introduction to Type Theory – p.5/32

slide-26
SLIDE 26

Overview

Examples for programming with dependent types:

An Introduction to Type Theory – p.5/32

slide-27
SLIDE 27

Overview

Examples for programming with dependent types:

– safe access to lists/vectors

An Introduction to Type Theory – p.5/32

slide-28
SLIDE 28

Overview

Examples for programming with dependent types:

– safe access to lists/vectors

✂ ✄

– safe eval

An Introduction to Type Theory – p.5/32

slide-29
SLIDE 29

Overview

Examples for programming with dependent types:

– safe access to lists/vectors

✂ ✄

– safe eval

  • – generic equality

An Introduction to Type Theory – p.5/32

slide-30
SLIDE 30

Overview

Examples for programming with dependent types:

– safe access to lists/vectors

✂ ✄

– safe eval

  • – generic equality

Illustrating patterns in DTP

An Introduction to Type Theory – p.5/32

slide-31
SLIDE 31

Overview

Examples for programming with dependent types:

– safe access to lists/vectors

✂ ✄

– safe eval

  • – generic equality

Illustrating patterns in DTP

verify

,

✂ ✄

An Introduction to Type Theory – p.5/32

slide-32
SLIDE 32

Overview

Examples for programming with dependent types:

– safe access to lists/vectors

✂ ✄

– safe eval

  • – generic equality

Illustrating patterns in DTP

verify

,

✂ ✄

reflect

  • An Introduction to Type Theory – p.5/32
slide-33
SLIDE 33

Overview

Examples for programming with dependent types:

– safe access to lists/vectors

✂ ✄

– safe eval

  • – generic equality

Illustrating patterns in DTP

verify

,

✂ ✄

reflect

  • Emphasis on safe and efficient execution

An Introduction to Type Theory – p.5/32

slide-34
SLIDE 34

Overview

Examples for programming with dependent types:

– safe access to lists/vectors

✂ ✄

– safe eval

  • – generic equality

Illustrating patterns in DTP

verify

,

✂ ✄

reflect

  • Emphasis on safe and efficient execution

Using epigram currently developed by Conor, using ideas from

An Introduction to Type Theory – p.5/32

slide-35
SLIDE 35

Overview

Examples for programming with dependent types:

– safe access to lists/vectors

✂ ✄

– safe eval

  • – generic equality

Illustrating patterns in DTP

verify

,

✂ ✄

reflect

  • Emphasis on safe and efficient execution

Using epigram currently developed by Conor, using ideas from LEGO / OLEG

An Introduction to Type Theory – p.5/32

slide-36
SLIDE 36

Overview

Examples for programming with dependent types:

– safe access to lists/vectors

✂ ✄

– safe eval

  • – generic equality

Illustrating patterns in DTP

verify

,

✂ ✄

reflect

  • Emphasis on safe and efficient execution

Using epigram currently developed by Conor, using ideas from LEGO / OLEG ALF

An Introduction to Type Theory – p.5/32

slide-37
SLIDE 37

— no dependent types

let

✂ ✄ ☎ ✆ ✄ ✝ ✞✠✟ ✁ ✂ ✡ ✄ ☛ ✂ ✁
✂ ✂ ✆ ✡ ✄ ✂
✂ ✂ ✆ ✡ ☞ ✌ ✍

An Introduction to Type Theory – p.6/32

slide-38
SLIDE 38

— no dependent types

let

✆ ✄ ✝ ✞✠✟ ✁ ✂ ✡ ✄ ☛ ✂ ✁
✂ ✆ ✡ ✄ ✂
✂ ✆ ✡ ☞ ✌ ✍

Hindley-Milner: Type quantification and application can be made implicit.

An Introduction to Type Theory – p.6/32

slide-39
SLIDE 39

— no dependent types

let

✆ ✄ ✝ ✞✠✟ ✁ ✂ ✡ ✄ ☛ ✂ ✁
✂ ✆ ✡ ✄ ✂
✄ ✡ ☞ ✌ ✍
✄ ✄☎ ✆ ✡ ☞ ✌ ✍

Hindley-Milner: Type quantification and application can be made implicit. Split left hand sides using type information

An Introduction to Type Theory – p.6/32

slide-40
SLIDE 40

— no dependent types

let

✆ ✄ ✝ ✞✠✟ ✁ ✂ ✡ ✄ ☛ ✂ ✁
✂ ✆ ✡ ✄ ✂
✄ ✡ ☞ ✌ ✍
✄ ✄☎ ✆
✌ ✍
✄ ✄☎ ✆
✡ ✆ ☞ ✌ ✍

Hindley-Milner: Type quantification and application can be made implicit. Split left hand sides using type information

An Introduction to Type Theory – p.6/32

slide-41
SLIDE 41

— no dependent types

let

✆ ✄ ✝ ✞✠✟ ✁ ✂ ✡ ✄ ☛ ✂ ✁
✂ ✆ ✡ ✄ ✂
✄ ✡ ☞ ✌ ✍
✄ ✄☎ ✆
✌ ✄
✄ ✄☎ ✆
✡ ✆ ☞ ✌ ✍

Hindley-Milner: Type quantification and application can be made implicit. Split left hand sides using type information

An Introduction to Type Theory – p.6/32

slide-42
SLIDE 42

— no dependent types

let

✆ ✄ ✝ ✞✠✟ ✁ ✂ ✡ ✄ ☛ ✂ ✁
✂ ✆ ✡ ✄ ✂
✄ ✡ ☞ ✌ ✍
✄ ✄☎ ✆
✌ ✄
✄ ✄☎ ✆
✡ ✆ ☞ ✌
✂ ✄ ☎ ✡

Hindley-Milner: Type quantification and application can be made implicit. Split left hand sides using type information

An Introduction to Type Theory – p.6/32

slide-43
SLIDE 43

is not good

let

✆ ✄ ✝ ✞✠✟ ✁ ✂ ✡ ✄ ☛ ✂ ✁
✂ ✆ ✡ ✄ ✂
✄ ✡ ☞ ✌ ✍
✄ ✄☎ ✆
✌ ✄
✄ ✄☎ ✆
✡ ✆ ☞ ✌
✂ ✄☎ ✡

An Introduction to Type Theory – p.7/32

slide-44
SLIDE 44

is not good

let

✆ ✄ ✝ ✞✠✟ ✁ ✂ ✡ ✄ ☛ ✂ ✁
✂ ✆ ✡ ✄ ✂
✄ ✡ ☞ ✌ ✍
✄ ✄☎ ✆
✌ ✄
✄ ✄☎ ✆
✡ ✆ ☞ ✌
✂ ✄☎ ✡

The function

is partial

✂ ✄ ☎ ✆

leads to a runtime error.

An Introduction to Type Theory – p.7/32

slide-45
SLIDE 45

is not good

let

✆ ✄ ✝ ✞✠✟ ✁ ✂ ✡ ✄ ☛ ✂ ✁
✂ ✆ ✡ ✄ ✂
✄ ✡ ☞ ✌ ✍
✄ ✄☎ ✆
✌ ✄
✄ ✄☎ ✆
✡ ✆ ☞ ✌
✂ ✄☎ ✡

The function

is partial

✂ ✄ ☎ ✆

leads to a runtime error. Reason: The type of

is not informative enough.

An Introduction to Type Theory – p.7/32

slide-46
SLIDE 46

data types

data where

☛ ✂ ✁ ✄ ☎
☛ ✂ ✁ ✡ ✄ ☛ ✂ ✁ ✟ ✡ ✄ ☛ ✂ ✁

data

✂ ✄ ☎

where

✝ ✞✠✟ ✁ ✂ ✄ ☎ ✂ ✄ ☎
✝ ✞ ✟ ✁ ✂ ✂ ✄ ☎ ✄ ✄ ✂ ✄ ☎ ✄ ✝ ✞ ✟ ✁ ✂ ✁ ✂
✄☎ ✄ ✝ ✞✠✟ ✁ ✂

An Introduction to Type Theory – p.8/32

slide-47
SLIDE 47

data types

data where

☛ ✂ ✁ ✄ ☎
☛ ✂ ✁ ✡ ✄ ☛ ✂ ✁ ✟ ✡ ✄ ☛ ✂ ✁

data

✂ ✄ ☎

where

✝ ✞✠✟ ✁ ✂ ✄ ☎
✄ ✄ ✝ ✞ ✟ ✁ ✂ ✄ ✄ ✂ ✄ ☎ ✄ ✝ ✞ ✟ ✁ ✂ ✁ ✂
✄ ✄☎ ✄ ✝ ✞✠✟ ✁ ✂

An Introduction to Type Theory – p.8/32

slide-48
SLIDE 48

Better data types, better

An Introduction to Type Theory – p.9/32

slide-49
SLIDE 49

Better data types, better

data

☞✂✁ ✄

where

✂ ✝ ✛
☞✂✁ ✄ ☎ ☛ ✆ ✁ ✂ ✝ ✛ ✓ ✜
☞✂✁ ✄ ✝ ✁ ✂ ✝ ✛
☛ ✆ ✝ ✁ ✂ ✝ ✛ ✓ ✜

An Introduction to Type Theory – p.9/32

slide-50
SLIDE 50

Better data types, better

data

☞✂✁ ✄

where

✂ ✝ ✛
☞✂✁ ✄ ☎ ☛ ✆ ✁ ✂ ✝ ✛ ✓ ✜
☞✂✁ ✄ ✝ ✁ ✂ ✝ ✛
☛ ✆ ✝ ✁ ✂ ✝ ✛ ✓ ✜

data

☞✂✁ ✄

where

✁ ✑ ✙
✄ ✂ ✛ ✝ ✌ ✁ ✁ ✑ ✙
☞✂✁ ✄ ✠ ✁
  • ✠✄
✁ ✁ ✑ ✙
✙ ✒ ✛ ✜ ✆ ✠ ✠ ✄ ✁ ✁ ✑ ✙

An Introduction to Type Theory – p.9/32

slide-51
SLIDE 51

Better data types, better

data

☞✂✁ ✄

where

✂ ✝ ✛
☞✂✁ ✄ ☎ ☛ ✁ ✂ ✝ ✛ ✓ ✜
✝ ✁ ✂ ✝ ✛
☛ ✝ ✁ ✂ ✝ ✛ ✓ ✜

data

☞✂✁ ✄

where

✁ ✑ ✙
✄ ✂ ✛ ✝ ✌ ✁ ✁ ✑ ✙
✠ ✁
  • ✠✄
✁ ✁ ✑ ✙
✙ ✒ ✛ ✜ ✠ ✠ ✄ ✁ ✁ ✑ ✙

An Introduction to Type Theory – p.9/32

slide-52
SLIDE 52

Better data types, better

data

☞✂✁ ✄

where

✂ ✝ ✛
☞✂✁ ✄ ☎ ☛ ✁ ✂ ✝ ✛ ✓ ✜
✝ ✁ ✂ ✝ ✛
☛ ✝ ✁ ✂ ✝ ✛ ✓ ✜

data

☞✂✁ ✄

where

✁ ✑ ✙
✄ ✂ ✛ ✝ ✌ ✁ ✁ ✑ ✙
✠ ✁
  • ✠✄
✁ ✁ ✑ ✙
✙ ✒ ✛ ✜ ✠ ✠ ✄ ✁ ✁ ✑ ✙

let

☞✂✁ ✄
✁ ✑ ✙
✁ ✂ ✝ ✛
✄ ✁ ✆
  • An Introduction to Type Theory – p.9/32
slide-53
SLIDE 53

Better data types, better

data

☞✂✁ ✄

where

✂ ✝ ✛
☞✂✁ ✄ ☎ ☛ ✁ ✂ ✝ ✛ ✓ ✜
✝ ✁ ✂ ✝ ✛
☛ ✝ ✁ ✂ ✝ ✛ ✓ ✜

data

☞✂✁ ✄

where

✁ ✑ ✙
✄ ✂ ✛ ✝ ✌ ✁ ✁ ✑ ✙
✠ ✁
  • ✠✄
✁ ✁ ✑ ✙
✙ ✒ ✛ ✜ ✠ ✠ ✄ ✁ ✁ ✑ ✙

let

✁ ✑ ✙
✁ ✂ ✝ ✛
✄ ✁
  • An Introduction to Type Theory – p.9/32
slide-54
SLIDE 54

Better data types, better

data

☞✂✁ ✄

where

✂ ✝ ✛
☞✂✁ ✄ ☎ ☛ ✁ ✂ ✝ ✛ ✓ ✜
✝ ✁ ✂ ✝ ✛
☛ ✝ ✁ ✂ ✝ ✛ ✓ ✜

data

☞✂✁ ✄

where

✁ ✑ ✙
✄ ✂ ✛ ✝ ✌ ✁ ✁ ✑ ✙
✠ ✁
  • ✠✄
✁ ✁ ✑ ✙
✙ ✒ ✛ ✜ ✠ ✠ ✄ ✁ ✁ ✑ ✙

let

✁ ✑ ✙
✁ ✂ ✝ ✛
✄ ✁
✄ ✁

An Introduction to Type Theory – p.9/32

slide-55
SLIDE 55

Better data types, better

data

☞✂✁ ✄

where

✂ ✝ ✛
☞✂✁ ✄ ☎ ☛ ✁ ✂ ✝ ✛ ✓ ✜
✝ ✁ ✂ ✝ ✛
☛ ✝ ✁ ✂ ✝ ✛ ✓ ✜

data

☞✂✁ ✄

where

✁ ✑ ✙
✄ ✂ ✛ ✝ ✌ ✁ ✁ ✑ ✙
✠ ✁
  • ✠✄
✁ ✁ ✑ ✙
✙ ✒ ✛ ✜ ✠ ✠ ✄ ✁ ✁ ✑ ✙

let

✁ ✑ ✙
✁ ✂ ✝ ✛
✄ ✁
✄ ✁
✂ ✛ ✄ ✁
✜ ☛ ✝ ✔

An Introduction to Type Theory – p.9/32

slide-56
SLIDE 56

Better data types, better

data

☞✂✁ ✄

where

✂ ✝ ✛
☞✂✁ ✄ ☎ ☛ ✁ ✂ ✝ ✛ ✓ ✜
✝ ✁ ✂ ✝ ✛
☛ ✝ ✁ ✂ ✝ ✛ ✓ ✜

data

☞✂✁ ✄

where

✁ ✑ ✙
✄ ✂ ✛ ✝ ✌ ✁ ✁ ✑ ✙
✠ ✁
  • ✠✄
✁ ✁ ✑ ✙
✙ ✒ ✛ ✜ ✠ ✠ ✄ ✁ ✁ ✑ ✙

let

✁ ✑ ✙
✁ ✂ ✝ ✛
✄ ✁
✄ ✁ ✓ ✂ ✙ ✒ ✛ ✜ ✠ ✠✄ ✔ ☎ ☛
✂ ✛ ✄ ✁
✜ ☛ ✝ ✔

An Introduction to Type Theory – p.9/32

slide-57
SLIDE 57

Better data types, better

data

☞✂✁ ✄

where

✂ ✝ ✛
☞✂✁ ✄ ☎ ☛ ✁ ✂ ✝ ✛ ✓ ✜
✝ ✁ ✂ ✝ ✛
☛ ✝ ✁ ✂ ✝ ✛ ✓ ✜

data

☞✂✁ ✄

where

✁ ✑ ✙
✄ ✂ ✛ ✝ ✌ ✁ ✁ ✑ ✙
✠ ✁
  • ✠✄
✁ ✁ ✑ ✙
✙ ✒ ✛ ✜ ✠ ✠ ✄ ✁ ✁ ✑ ✙

let

✁ ✑ ✙
✁ ✂ ✝ ✛
✄ ✁
✄ ✁ ✓ ✂ ✙ ✒ ✛ ✜ ✠ ✠ ✄ ✔ ☎ ☛
✂ ✛ ✄ ✁ ✓ ✂ ✙ ✒ ✛ ✜ ✠ ✠ ✄ ✔ ✓ ✜ ☛ ✝ ✔

An Introduction to Type Theory – p.9/32

slide-58
SLIDE 58

Better data types, better

data

☞✂✁ ✄

where

✂ ✝ ✛
☞✂✁ ✄ ☎ ☛ ✁ ✂ ✝ ✛ ✓ ✜
✝ ✁ ✂ ✝ ✛
☛ ✝ ✁ ✂ ✝ ✛ ✓ ✜

data

☞✂✁ ✄

where

✁ ✑ ✙
✄ ✂ ✛ ✝ ✌ ✁ ✁ ✑ ✙
✠ ✁
  • ✠✄
✁ ✁ ✑ ✙
✙ ✒ ✛ ✜ ✠ ✠ ✄ ✁ ✁ ✑ ✙

let

✁ ✑ ✙
✁ ✂ ✝ ✛
✄ ✁
✄ ✁ ✓ ✂ ✙ ✒ ✛ ✜ ✠ ✠✄ ✔ ☎ ☛
✠ ✛ ✄ ✁ ✓ ✂ ✙ ✒ ✛ ✜ ✠ ✠✄ ✔ ✓ ✜ ☛ ✝ ✔
✛ ✄ ✁ ✠✄ ✝ ✛ ✄ ✁

is a total function.

An Introduction to Type Theory – p.9/32

slide-59
SLIDE 59

Better data types, better

data

☞✂✁ ✄

where

✂ ✝ ✛
☞✂✁ ✄ ☎ ☛ ✁ ✂ ✝ ✛ ✓ ✜
✝ ✁ ✂ ✝ ✛
☛ ✝ ✁ ✂ ✝ ✛ ✓ ✜

data

☞✂✁ ✄

where

✁ ✑ ✙
✄ ✂ ✛ ✝ ✌ ✁ ✁ ✑ ✙
✠ ✁
  • ✠✄
✁ ✁ ✑ ✙
✙ ✒ ✛ ✜ ✠ ✠ ✄ ✁ ✁ ✑ ✙

let

✁ ✑ ✙
✁ ✂ ✝ ✛
✄ ✁
✄ ✁ ✓ ✂ ✙ ✒ ✛ ✜ ✠ ✠✄ ✔ ☎ ☛
✠ ✛ ✄ ✁ ✓ ✂ ✙ ✒ ✛ ✜ ✠ ✠✄ ✔ ✓ ✜ ☛ ✝ ✔
✛ ✄ ✁ ✠✄ ✝ ✛ ✄ ✁

is a total function.

✛ ✄ ✁
✂ ✄ ☎ ✆

is not well-typed.

An Introduction to Type Theory – p.9/32

slide-60
SLIDE 60

Verify

An Introduction to Type Theory – p.10/32

slide-61
SLIDE 61

Verify

How can we use

  • n lists of unknown length

user input,. . . ?

An Introduction to Type Theory – p.10/32

slide-62
SLIDE 62

Verify

How can we use

  • n lists of unknown length

user input,. . . ?

let

✡ ✄
☛ ✂ ✁ ✁
✞ ✂ ✄ ✡
☎ ✂ ✄ ✆

An Introduction to Type Theory – p.10/32

slide-63
SLIDE 63

Verify

How can we use

  • n lists of unknown length

user input,. . . ?

let

✡ ✄
☛ ✂ ✁ ✁
✞ ✂ ✄ ✡
☎ ✂ ✄ ✆
✆ ✁
✞ ✂ ✄ ✡
✌ ✍

An Introduction to Type Theory – p.10/32

slide-64
SLIDE 64

Verify

How can we use

  • n lists of unknown length

user input,. . . ?

let

✡ ✄
☛ ✂ ✁ ✁
✞ ✂ ✄ ✡
☎ ✂ ✄ ✆
✆ ✁
✞ ✂ ✄
✌ ✍ ✁
✞ ✂ ✄
✡ ✆
✌ ✍

An Introduction to Type Theory – p.10/32

slide-65
SLIDE 65

Verify

How can we use

  • n lists of unknown length

user input,. . . ?

let

✡ ✄
☛ ✂ ✁ ✁
✞ ✂ ✄ ✡
☎ ✂ ✄ ✆
✆ ✁
✞ ✂ ✄
✁ ✂ ✞
✞ ✂ ✄
✡ ✆
✌ ✍

An Introduction to Type Theory – p.10/32

slide-66
SLIDE 66

Verify

How can we use

  • n lists of unknown length

user input,. . . ?

let

✡ ✄
☛ ✂ ✁ ✁
✞ ✂ ✄ ✡
☎ ✂ ✄ ✆
✆ ✁
✞ ✂ ✄
✁ ✂ ✞
✞ ✂ ✄
✡ ✆
✌ ✍ ✁
✞ ✂ ✄
✡ ✆
☞ ✌ ✍

An Introduction to Type Theory – p.10/32

slide-67
SLIDE 67

Verify

How can we use

  • n lists of unknown length

user input,. . . ?

let

✡ ✄
☛ ✂ ✁ ✁
✞ ✂ ✄ ✡
☎ ✂ ✄ ✆
✆ ✁
✞ ✂ ✄
✁ ✂ ✞
✞ ✂ ✄
✡ ✆
✟ ✁
✞ ✂ ✄
✡ ✆
☞ ✌ ✍

An Introduction to Type Theory – p.10/32

slide-68
SLIDE 68

Verify

How can we use

  • n lists of unknown length

user input,. . . ?

let

✡ ✄
☛ ✂ ✁ ✁
✞ ✂ ✄ ✡
☎ ✂ ✄ ✆
✆ ✁
✞ ✂ ✄
✁ ✂ ✞
✞ ✂ ✄
✡ ✆
✟ ✁
✞ ✂ ✄
✡ ✆
✞ ✂ ✄ ✡
✌ ✍

An Introduction to Type Theory – p.10/32

slide-69
SLIDE 69

Verify

How can we use

  • n lists of unknown length

user input,. . . ?

let

✡ ✄
☛ ✂ ✁ ✁
✞ ✂ ✄ ✡
☎ ✂ ✄ ✆
✆ ✁
✞ ✂ ✄
✁ ✂ ✞
✞ ✂ ✄
✡ ✆
✟ ✁
✞ ✂ ✄
✡ ✆
✞ ✂ ✄ ✡
✁ ✂ ✞
✌ ✍
✟ ✁
✌ ✍

An Introduction to Type Theory – p.10/32

slide-70
SLIDE 70

Verify

How can we use

  • n lists of unknown length

user input,. . . ?

let

✡ ✄
☛ ✂ ✁ ✁
✞ ✂ ✄ ✡
☎ ✂ ✄ ✆
✆ ✁
✞ ✂ ✄
✁ ✂ ✞
✞ ✂ ✄
✡ ✆
✟ ✁
✞ ✂ ✄
✡ ✆
✞ ✂ ✄ ✡
✁ ✂ ✞
✁ ✂ ✞
✟ ✁
✌ ✍

An Introduction to Type Theory – p.10/32

slide-71
SLIDE 71

Verify

How can we use

  • n lists of unknown length

user input,. . . ?

let

✡ ✄
☛ ✂ ✁ ✁
✞ ✂ ✄ ✡
☎ ✂ ✄ ✆
✆ ✁
✞ ✂ ✄
✁ ✂ ✞
✞ ✂ ✄
✡ ✆
✟ ✁
✞ ✂ ✄
✡ ✆
✞ ✂ ✄ ✡
✁ ✂ ✞
✁ ✂ ✞
✟ ✁
✟ ✁

An Introduction to Type Theory – p.10/32

slide-72
SLIDE 72

Going further

An Introduction to Type Theory – p.11/32

slide-73
SLIDE 73

Going further

The type of

✞ ✂ ✄

is not informative enough for some of its potential applications.

An Introduction to Type Theory – p.11/32

slide-74
SLIDE 74

Going further

The type of

✞ ✂ ✄

is not informative enough for some of its potential applications. How is

✟ ✁
✞ ✂ ✄ ✡
  • related to
  • ?

An Introduction to Type Theory – p.11/32

slide-75
SLIDE 75

Going further

The type of

✞ ✂ ✄

is not informative enough for some of its potential applications. How is

✟ ✁
✞ ✂ ✄ ✡
  • related to
  • ?

When does

✞ ✂ ✄

return

✁ ✂ ✞
  • ?

An Introduction to Type Theory – p.11/32

slide-76
SLIDE 76
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

An Introduction to Type Theory – p.12/32

slide-77
SLIDE 77
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

data

✝ ✁ ☞✂✁ ✄

where

✗ ✛ ✁
✁ ✄ ✝ ✁ ✂ ✝ ✛
✒ ✗ ✛ ✁
✗ ✛ ✁
✂ ✁ ✌ ✝ ✔ ✝ ✄
☞✂✁ ✄ ✄ ✒ ✒
  • ✝☎✄
✗ ✛ ✁
✝ ✔

An Introduction to Type Theory – p.12/32

slide-78
SLIDE 78
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

data

✝ ✁ ☞✂✁ ✄

where

✗ ✛ ✁
✁ ✄ ✝ ✁ ✂ ✝ ✛
✒ ✗ ✛ ✁
✗ ✛ ✁
✂ ✁ ✌ ✝ ✔ ✝ ✄
☞✂✁ ✄ ✄ ✒ ✒
  • ✝☎✄
✗ ✛ ✁
✝ ✔

let

✝ ✁ ☞✂✁ ✄ ✂ ✑ ☎ ✝
✗ ✛ ✁

An Introduction to Type Theory – p.12/32

slide-79
SLIDE 79
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

data

✝ ✁ ☞✂✁ ✄

where

✗ ✛ ✁
✁ ✄ ✝ ✁ ✂ ✝ ✛
✒ ✗ ✛ ✁
✗ ✛ ✁
✂ ✁ ✌ ✝ ✔ ✝ ✄
☞✂✁ ✄ ✄ ✒ ✒
  • ✝☎✄
✗ ✛ ✁
✝ ✔

let

✝ ✁ ☞✂✁ ✄ ✂ ✑ ☎ ✝
✗ ✛ ✁
✂ ✑ ☎ ✝

An Introduction to Type Theory – p.12/32

slide-80
SLIDE 80
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

data

✝ ✁ ☞✂✁ ✄

where

✗ ✛ ✁
✁ ✄ ✝ ✁ ✂ ✝ ✛
✒ ✗ ✛ ✁
✗ ✛ ✁
✂ ✁ ✌ ✝ ✔ ✝ ✄
☞✂✁ ✄ ✄ ✒ ✒
  • ✝☎✄
✗ ✛ ✁
✝ ✔

let

✝ ✁ ☞✂✁ ✄ ✂ ✑ ☎ ✝
✗ ✛ ✁
✂ ✑ ☎ ✝
☎ ✝
✂ ✂ ✑ ☎ ✝
✓ ✜

An Introduction to Type Theory – p.12/32

slide-81
SLIDE 81
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

data

✝ ✁ ☞✂✁ ✄

where

✗ ✛ ✁
✁ ✄ ✝ ✁ ✂ ✝ ✛
✒ ✗ ✛ ✁
✗ ✛ ✁
✂ ✁ ✌ ✝ ✔ ✝ ✄
☞✂✁ ✄ ✄ ✒ ✒
  • ✝☎✄
✗ ✛ ✁
✝ ✔

let

✝ ✁ ☞✂✁ ✄ ✂ ✑ ☎ ✝
✗ ✛ ✁
✂ ✑ ☎ ✝
☎ ✝
✄ ✒ ✒
  • ✝☎✄
☎ ✝ ✂ ✑ ☎ ✝
✓ ✜

An Introduction to Type Theory – p.12/32

slide-82
SLIDE 82
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

data

✝ ✁ ☞✂✁ ✄

where

✗ ✛ ✁
✁ ✄ ✝ ✁ ✂ ✝ ✛
✒ ✗ ✛ ✁
✗ ✛ ✁
✂ ✁ ✌ ✝ ✔ ✝ ✄
☞✂✁ ✄ ✄ ✒ ✒
  • ✝☎✄
✗ ✛ ✁
✝ ✔

let

✝ ✁ ☞✂✁ ✄ ✂ ✑ ☎ ✝
✗ ✛ ✁
✂ ✑ ☎ ✝
☎ ✝
✄ ✒ ✒
  • ✝☎✄
☎ ✝ ✂ ✑ ☎ ✝
✓ ✜
✂ ✂ ✑ ☎ ✝
✓ ✜
✓ ✜ ✝ ✔

An Introduction to Type Theory – p.12/32

slide-83
SLIDE 83
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

data

✝ ✁ ☞✂✁ ✄

where

✗ ✛ ✁
✁ ✄ ✝ ✁ ✂ ✝ ✛
✒ ✗ ✛ ✁
✗ ✛ ✁
✂ ✁ ✌ ✝ ✔ ✝ ✄
☞✂✁ ✄ ✄ ✒ ✒
  • ✝☎✄
✗ ✛ ✁
✝ ✔

let

✝ ✁ ☞✂✁ ✄ ✂ ✑ ☎ ✝
✗ ✛ ✁
✂ ✑ ☎ ✝
☎ ✝
✄ ✒ ✒
  • ✝☎✄
☎ ✝ ✂ ✑ ☎ ✝
✓ ✜
✂ ✒ ✗ ✛ ✁
☛ ✂ ✑ ☎ ✝
✓ ✜
✓ ✜ ✝ ✔

An Introduction to Type Theory – p.12/32

slide-84
SLIDE 84
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

data

✝ ✁ ☞✂✁ ✄

where

✗ ✛ ✁
✁ ✄ ✝ ✁ ✂ ✝ ✛
✒ ✗ ✛ ✁
✗ ✛ ✁
✂ ✁ ✌ ✝ ✔ ✝ ✄
☞✂✁ ✄ ✄ ✒ ✒
  • ✝☎✄
✗ ✛ ✁
✝ ✔

let

✝ ✁ ☞✂✁ ✄ ✂ ✑ ☎ ✝
✗ ✛ ✁
✂ ✑ ☎ ✝
☎ ✝
✄ ✒ ✒
  • ✝☎✄
☎ ✝ ✂ ✑ ☎ ✝
✓ ✜
✂ ✒ ✗ ✛ ✁
☛ ✂ ✑ ☎ ✝
✓ ✜
✓ ✜ ✝ ✔
✑ ☎ ✝

An Introduction to Type Theory – p.12/32

slide-85
SLIDE 85
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

data

✝ ✁ ☞✂✁ ✄

where

✗ ✛ ✁
✁ ✄ ✝ ✁ ✂ ✝ ✛
✒ ✗ ✛ ✁
✗ ✛ ✁
✂ ✁ ✌ ✝ ✔ ✝ ✄
☞✂✁ ✄ ✄ ✒ ✒
  • ✝☎✄
✗ ✛ ✁
✝ ✔

let

✝ ✁ ☞✂✁ ✄ ✂ ✑ ☎ ✝
✗ ✛ ✁
✂ ✑ ☎ ✝
☎ ✝
✄ ✒ ✒
  • ✝☎✄
☎ ✝ ✂ ✑ ☎ ✝
✓ ✜
✂ ✒ ✗ ✛ ✁
☛ ✂ ✑ ☎ ✝
✓ ✜
✓ ✜ ✝ ✔
✑ ☎ ✝
✂ ✑ ☎ ✝
✓ ✜
✓ ✜ ✓
✝ ✔ ✔ ✕ ✄ ✒ ✒
  • ✝☎✄
✂ ✂ ✑ ☎ ✝
✓ ✜
✓ ✂ ✁ ✌ ✝ ✔ ✕ ✂ ✒ ✗ ✛ ✁

An Introduction to Type Theory – p.12/32

slide-86
SLIDE 86
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

data

✝ ✁ ☞✂✁ ✄

where

✗ ✛ ✁
✁ ✄ ✝ ✁ ✂ ✝ ✛
✒ ✗ ✛ ✁
✗ ✛ ✁
✂ ✁ ✌ ✝ ✔ ✝ ✄
☞✂✁ ✄ ✄ ✒ ✒
  • ✝☎✄
✗ ✛ ✁
✝ ✔

let

✝ ✁ ☞✂✁ ✄ ✂ ✑ ☎ ✝
✗ ✛ ✁
✂ ✑ ☎ ✝
☎ ✝
✄ ✒ ✒
  • ✝☎✄
☎ ✝ ✂ ✑ ☎ ✝
✓ ✜
✂ ✒ ✗ ✛ ✁
☛ ✂ ✑ ☎ ✝
✓ ✜
✓ ✜ ✝ ✔
✑ ☎ ✝
✂ ✑ ☎ ✝
✓ ✜
✓ ✜ ✓
✝ ✔ ✔ ✕ ✄ ✒ ✒
  • ✝☎✄
✄ ✒ ✒
  • ✝☎✄
✓ ✜
✝ ✂ ✑ ☎ ✝
✓ ✜
✓ ✂ ✁ ✌ ✝ ✔ ✕ ✂ ✒ ✗ ✛ ✁

An Introduction to Type Theory – p.12/32

slide-87
SLIDE 87
✂ ✄

improved.

let

✝ ✁ ✂ ✝ ✛
✁ ✌ ✝ ✁ ☞✂✁ ✄ ✂ ✁ ✌ ☎ ☛
☎ ✂ ✁ ✌ ✓ ✜ ☛ ✝ ✔
✜ ✓ ✂ ✁ ✌ ✝ ✔

data

✝ ✁ ☞✂✁ ✄

where

✗ ✛ ✁
✁ ✄ ✝ ✁ ✂ ✝ ✛
✒ ✗ ✛ ✁
✗ ✛ ✁
✂ ✁ ✌ ✝ ✔ ✝ ✄
☞✂✁ ✄ ✄ ✒ ✒
  • ✝☎✄
✗ ✛ ✁
✝ ✔

let

✝ ✁ ☞✂✁ ✄ ✂ ✑ ☎ ✝
✗ ✛ ✁
✂ ✑ ☎ ✝
☎ ✝
✄ ✒ ✒
  • ✝☎✄
☎ ✝ ✂ ✑ ☎ ✝
✓ ✜
✂ ✒ ✗ ✛ ✁
☛ ✂ ✑ ☎ ✝
✓ ✜
✓ ✜ ✝ ✔
✑ ☎ ✝
✂ ✑ ☎ ✝
✓ ✜
✓ ✜ ✓
✝ ✔ ✔ ✕ ✄ ✒ ✒
  • ✝☎✄
✄ ✒ ✒
  • ✝☎✄
✓ ✜
✝ ✂ ✑ ☎ ✝
✓ ✜
✓ ✂ ✁ ✌ ✝ ✔ ✕ ✂ ✒ ✗ ✛ ✁
✂ ✒ ✗ ✛ ✁ ✓ ✜
✓ ✜ ☛ ✝ ✔

An Introduction to Type Theory – p.12/32

slide-88
SLIDE 88

Definitional equality

An Introduction to Type Theory – p.13/32

slide-89
SLIDE 89

Definitional equality

The typing of

✞ ✂ ✄

depends on the equations:

✁ ✡
✁ ✆
✁ ✟

An Introduction to Type Theory – p.13/32

slide-90
SLIDE 90

Definitional equality

The typing of

✞ ✂ ✄

depends on the equations:

✁ ✡
✁ ✆
✁ ✟

This equations need to be true definitionally.

An Introduction to Type Theory – p.13/32

slide-91
SLIDE 91

Definitional equality

The typing of

✞ ✂ ✄

depends on the equations:

✁ ✡
✁ ✆
✁ ✟

This equations need to be true definitionally. If we need

we have to use propositional equality.

An Introduction to Type Theory – p.13/32

slide-92
SLIDE 92

Propositional equality

An Introduction to Type Theory – p.14/32

slide-93
SLIDE 93

Propositional equality

data

✂ ✄ ☎ ✄ ✄

where

☎ ✄ ✄ ✂ ✁
✄ ✄ ✄

An Introduction to Type Theory – p.14/32

slide-94
SLIDE 94

Propositional equality

data

✂ ✄ ☎ ✄ ✄

where

☎ ✄ ✄ ✂ ✁
✄ ✄ ✄

let

✡ ✄ ☛ ✂ ✁ ✂
  • ✂✁
✡ ✄ ✡
✌ ✁
✡ ✆
☞ ✌ ✁

An Introduction to Type Theory – p.14/32

slide-95
SLIDE 95

Propositional equality

data

✂ ✄ ☎ ✄ ✄

where

☎ ✄ ✄ ✂ ✁
✄ ✄ ✄

let

✡ ✄ ☛ ✂ ✁ ✂
  • ✂✁
✡ ✄ ✡
✌ ✁
✡ ✆
☞ ✌ ✁

let

✄ ✂ ✌ ☎ ✂ ✄ ✁ ✄ ✟ ✁ ✆ ✟ ✁
✂ ✄ ✁
✁ ✆ ✟ ✁
✄ ✆ ✁ ✂ ☞ ✌ ✂

An Introduction to Type Theory – p.14/32

slide-96
SLIDE 96

Problems with

  • An Introduction to Type Theory – p.15/32
slide-97
SLIDE 97

Problems with

  • Programs cluttered with coercions.

An Introduction to Type Theory – p.15/32

slide-98
SLIDE 98

Problems with

  • Programs cluttered with coercions.

Programming requires theorem proving.

An Introduction to Type Theory – p.15/32

slide-99
SLIDE 99

Problems with

  • Programs cluttered with coercions.

Programming requires theorem proving. Equality on functions is not extensional, i.e.

let

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

cannot be derived.

An Introduction to Type Theory – p.15/32

slide-100
SLIDE 100

Solutions ?

An Introduction to Type Theory – p.16/32

slide-101
SLIDE 101

Solutions ?

In many cases the need for propositional equality can be avoided.

An Introduction to Type Theory – p.16/32

slide-102
SLIDE 102

Solutions ?

In many cases the need for propositional equality can be avoided. DML shows that many equalities needed in programming can be proven automatically. Proposal: Integrate an extensible constraint prover into the elaboration process.

An Introduction to Type Theory – p.16/32

slide-103
SLIDE 103

Solutions ?

In many cases the need for propositional equality can be avoided. DML shows that many equalities needed in programming can be proven automatically. Proposal: Integrate an extensible constraint prover into the elaboration process. The problem with extensional equality can be overcome using a different approach to equality.

An Introduction to Type Theory – p.16/32

slide-104
SLIDE 104

Eval

An Introduction to Type Theory – p.17/32

slide-105
SLIDE 105

Eval

Implement an evaluator for a simply typed object language.

An Introduction to Type Theory – p.17/32

slide-106
SLIDE 106

Eval

Implement an evaluator for a simply typed object language. We use type-checking to avoid run-time errors.

An Introduction to Type Theory – p.17/32

slide-107
SLIDE 107

Eval

Implement an evaluator for a simply typed object language. We use type-checking to avoid run-time errors. First we implement a simply typed version.

An Introduction to Type Theory – p.17/32

slide-108
SLIDE 108

Eval

Implement an evaluator for a simply typed object language. We use type-checking to avoid run-time errors. First we implement a simply typed version. Then a dependently typed version, exploiting the verify pattern.

An Introduction to Type Theory – p.17/32

slide-109
SLIDE 109

The object language

data where

✄ ✄ ☎ ✡ ✄ ☛ ✂ ✁ ✁
✁ ✡ ✄
✂ ✂ ✂ ✄ ✁ ✆ ✂ ✂ ✄

An Introduction to Type Theory – p.18/32

slide-110
SLIDE 110

The object language

data where

✄ ✄ ☎ ✡ ✄ ☛ ✂ ✁ ✁
✁ ✡ ✄
✂ ✂ ✂ ✄ ✁ ✆ ✂ ✂ ✄

data where

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

An Introduction to Type Theory – p.18/32

slide-111
SLIDE 111

Object types

data where

✄ ☎
✁ ✄
✆ ✂ ✂ ✄ ✄

An Introduction to Type Theory – p.19/32

slide-112
SLIDE 112

Object types

data where

✄ ☎
✁ ✄
✆ ✂ ✂ ✄ ✄

let

✄ ✄
✞ ✂ ✄ ✄ ✄ ☎ ✂ ✄ ✆
✆ ✆ ✆

An Introduction to Type Theory – p.19/32

slide-113
SLIDE 113

Eval — simply typed

let

✍ ✁
✑ ✂ ✁ ✌ ✍ ✁ ✁ ✁ ✌

An Introduction to Type Theory – p.20/32

slide-114
SLIDE 114

Eval — simply typed

let

✍ ✁
✑ ✂ ✁ ✌ ✍ ✁ ✁ ✁ ✌ ✑ ✂ ✁ ✌ ✓ ✄ ✂ ✁ ✌
✂ ✁ ✌ ✓ ✄ ✝
✁ ✂ ✁ ✄ ✔
✂ ✁ ✌ ✍ ✕ ✂ ✛ ✁ ✄
✂ ✕ ✂ ✂ ✒ ✒ ✌ ✄✆☎ ✗ ✑
✑ ✂ ✁ ✌ ✁ ✂ ✕ ✂ ✂ ✒ ✒ ✌
✌ ✜ ✑
✑ ✂ ✁ ✌ ✁ ✄ ✑ ✂ ✁ ✌ ✓ ✄ ✁ ✁ ✁ ✍ ✁ ✔
✂ ✁ ✌ ✍ ✕ ✂ ✛ ✁ ✄ ☎
✂ ✁ ✌ ✁ ✕ ✂ ✛ ✁ ✄
✂ ✛ ✁ ✄ ✓ ☎ ✆
✕ ✂ ✂ ✒ ✒ ✌✆
✂ ✕ ✂ ✂ ✒ ✒ ✌ ✆

An Introduction to Type Theory – p.20/32

slide-115
SLIDE 115

Safe eval ?

let

✄ ✄
✂ ✄ ✄ ✄ ☎ ✂ ✄ ✆

An Introduction to Type Theory – p.21/32

slide-116
SLIDE 116

Safe eval ?

let

✄ ✄
✂ ✄ ✄ ✄ ☎ ✂ ✄ ✆
✄ ✟
✂ ✄ ✄
✞ ✂ ✄ ✄
✟ ✁ ☎ ☞ ✌
✟ ✁
✂ ✄ ☎ ✆
✁ ✂ ✞
✁ ✂ ✞
  • An Introduction to Type Theory – p.21/32
slide-117
SLIDE 117

Safe eval ?

An Introduction to Type Theory – p.22/32

slide-118
SLIDE 118

Safe eval ?

We know that

✂ ✄

will never crash . . .

An Introduction to Type Theory – p.22/32

slide-119
SLIDE 119

Safe eval ?

We know that

✂ ✄

will never crash . . . . . . but the compiler doesn’t!

An Introduction to Type Theory – p.22/32

slide-120
SLIDE 120

Safe eval ?

We know that

✂ ✄

will never crash . . . . . . but the compiler doesn’t!

✂ ✄

is inefficient: Values carry tags at runtime

An Introduction to Type Theory – p.22/32

slide-121
SLIDE 121

Safe eval ?

We know that

✂ ✄

will never crash . . . . . . but the compiler doesn’t!

✂ ✄

is inefficient: Values carry tags at runtime

✂ ✄

checks the tags

An Introduction to Type Theory – p.22/32

slide-122
SLIDE 122

Object language using dependent types

An Introduction to Type Theory – p.23/32

slide-123
SLIDE 123

Object language using dependent types

data

✠ ✁

where

✁ ✌ ✠ ✁ ✄
☞✂✁ ✄ ✂ ✛ ✁ ✄
✁ ✌ ✛ ✁ ✄ ✆ ✁
✒ ✌ ✂ ✂ ✒ ✒ ✌ ✆ ✁
✁ ✌ ✂ ✒ ✒ ✌

An Introduction to Type Theory – p.23/32

slide-124
SLIDE 124

Object language using dependent types

data

✠ ✁

where

✁ ✌ ✠ ✁ ✄
☞✂✁ ✄ ✂ ✛ ✁ ✄
✁ ✌ ✛ ✁ ✄ ✆ ✁
✒ ✌ ✂ ✂ ✒ ✒ ✌ ✆ ✁
✁ ✌ ✂ ✒ ✒ ✌

data

✠ ✁ ✄

where

✠ ✁ ✄

An Introduction to Type Theory – p.23/32

slide-125
SLIDE 125

Object language using dependent types

data

✠ ✁

where

✁ ✌ ✠ ✁ ✄
☞✂✁ ✄ ✂ ✛ ✁ ✄
✁ ✌ ✛ ✁ ✄ ✆ ✁
✒ ✌ ✂ ✂ ✒ ✒ ✌ ✆ ✁
✁ ✌ ✂ ✒ ✒ ✌

data

✠ ✁ ✄

where

✠ ✁ ✄
✁ ✌ ✠ ✄ ✂ ✁ ✌
✠ ✍ ✁
✂ ✒ ✒ ✌ ✁ ✂ ✄ ✁ ✄ ✁
✠ ✄ ✝
✁ ✂ ✁ ✄ ✁
✠ ✍ ✄ ✁ ✄ ✁
✛ ✁ ✄ ✄ ✁ ✁ ✁ ✍ ✁ ✁
✛ ✁ ✄

An Introduction to Type Theory – p.23/32

slide-126
SLIDE 126

Eval — dependently

let

✍ ✁
✠ ✑ ✂ ✁ ✌ ✍ ✁ ✁ ✁ ✌ ✠

An Introduction to Type Theory – p.24/32

slide-127
SLIDE 127

Eval — dependently

let

✍ ✁
✠ ✑ ✂ ✁ ✌ ✍ ✁ ✁ ✁ ✌ ✠ ✑ ✂ ✁ ✌ ✓ ✄ ✂ ✁ ✌
✂ ✁ ✌ ✓ ✄ ✝
✁ ✂ ✁ ✄ ✔
✂ ✁ ✌ ✍ ✕ ✂ ✂ ✒ ✒ ✌ ✄✆☎ ✗ ✑
✑ ✂ ✁ ✌ ✁ ✂ ✕ ✂ ✂ ✒ ✒ ✌
✌ ✜ ✑
✑ ✂ ✁ ✌ ✁ ✄ ✑ ✂ ✁ ✌ ✓ ✄ ✁ ✁ ✁ ✍ ✁ ✔
✂ ✁ ✌ ✍ ✕ ✂ ✛ ✁ ✄ ☎
✂ ✁ ✌ ✁ ✕ ✂ ✛ ✁ ✄
✂ ✛ ✁ ✄ ✓ ☎ ✆

An Introduction to Type Theory – p.24/32

slide-128
SLIDE 128

Safe eval !

An Introduction to Type Theory – p.25/32

slide-129
SLIDE 129

Safe eval !

let

✍ ✁
✠ ✜ ✄✆☎ ✝✁ ✍ ✁
✂ ✂ ✂

An Introduction to Type Theory – p.25/32

slide-130
SLIDE 130

Safe eval !

let

✍ ✁
✠ ✜ ✄✆☎ ✝✁ ✍ ✁
✂ ✂ ✂

data

✍ ✁

where

✁ ✑ ☎ ✝
✍ ✁
✑ ☎ ☎ ✒ ☎ ✁ ✁ ✑ ☎ ✝
✍ ✍ ✁
✠ ✒
✁ ✁ ✑ ☎ ✝
✓ ✜ ✄ ☎ ✝✁ ✍ ✔

let

✍ ✁
✂ ✑ ☎ ✝
✍ ✁ ✁ ✑ ☎ ✝
✍ ✂ ✂ ✂

let

✍ ✁
✜ ✑ ✂ ✁ ✌ ✍ ✁ ✂✁ ✁ ✂ ✑ ✓ ✁ ✂ ✄ ☎✝✆ ✁ ✁ ✌ ✠ ✔ ✜ ✑ ✂ ✁ ✌ ✍
✑ ☎ ✝
✍ ✕ ✞ ✗ ✜ ✄ ✁
✞ ✗ ✜ ✄ ✓ ✑ ✂ ✁ ✌ ✁ ✔ ✕ ✑ ☎ ☎ ✒ ☎
✛ ✒ ✄ ✁ ✝ ✛ ✄

An Introduction to Type Theory – p.25/32

slide-131
SLIDE 131

Safe eval !

An Introduction to Type Theory – p.26/32

slide-132
SLIDE 132

Safe eval !

The compiler knows that

✂ ✄

will never crash.

An Introduction to Type Theory – p.26/32

slide-133
SLIDE 133

Safe eval !

The compiler knows that

✂ ✄

will never crash. We can generate a certificate (proof carrying code).

An Introduction to Type Theory – p.26/32

slide-134
SLIDE 134

Safe eval !

The compiler knows that

✂ ✄

will never crash. We can generate a certificate (proof carrying code).

✂ ✄

is efficient:

An Introduction to Type Theory – p.26/32

slide-135
SLIDE 135

Safe eval !

The compiler knows that

✂ ✄

will never crash. We can generate a certificate (proof carrying code).

✂ ✄

is efficient: No tags at runtime.

An Introduction to Type Theory – p.26/32

slide-136
SLIDE 136

Safe eval !

The compiler knows that

✂ ✄

will never crash. We can generate a certificate (proof carrying code).

✂ ✄

is efficient: No tags at runtime. No checking.

An Introduction to Type Theory – p.26/32

slide-137
SLIDE 137

Generic equality

An Introduction to Type Theory – p.27/32

slide-138
SLIDE 138

Generic equality

Implement a generic equality function for non nested, concrete data types

An Introduction to Type Theory – p.27/32

slide-139
SLIDE 139

Generic equality

Implement a generic equality function for non nested, concrete data types Usually requires a language extension (Generic Haskell)

An Introduction to Type Theory – p.27/32

slide-140
SLIDE 140

Generic equality

Implement a generic equality function for non nested, concrete data types Usually requires a language extension (Generic Haskell) Topic developed further in our (Conor and me) paper: Generic programming within dependently typed programming Working Conference on Generic Programming 2002

An Introduction to Type Theory – p.27/32

slide-141
SLIDE 141

Codes and data

An Introduction to Type Theory – p.28/32

slide-142
SLIDE 142

Codes and data

data where

✁ ✄

An Introduction to Type Theory – p.28/32

slide-143
SLIDE 143

Codes and data

data where

✁ ✄ ✗ ✛ ✝ ✄ ✁
✠ ✄ ✆ ✁
✒ ✁ ✠ ✆ ✁
✠ ✄ ✆ ✁
✜ ✗ ✁ ✠ ✆ ✁
☎ ✑ ✙ ✁

An Introduction to Type Theory – p.28/32

slide-144
SLIDE 144

Codes and data

data where

✁ ✄ ✗ ✛ ✝ ✄ ✁
✠ ✄ ✆ ✁
✒ ✁ ✠ ✆ ✁
✠ ✄ ✆ ✁
✜ ✗ ✁ ✠ ✆ ✁
☎ ✑ ✙ ✁

data

✠ ✁

where

✁ ✁ ✌
✁ ✄

An Introduction to Type Theory – p.28/32

slide-145
SLIDE 145

Codes and data

data where

✁ ✄ ✗ ✛ ✝ ✄ ✁
✠ ✄ ✆ ✁
✒ ✁ ✠ ✆ ✁
✠ ✄ ✆ ✁
✜ ✗ ✁ ✠ ✆ ✁
☎ ✑ ✙ ✁

data

✠ ✁

where

✁ ✁ ✌
✁ ✄ ✂ ✒ ✝ ✁ ✁ ✁ ✁ ✌
✛ ✝ ✄
✁ ✁ ✌
✁ ✁ ✁ ✁ ✌
✝ ☎
✁ ✁ ✁ ✌
✒ ✁ ✠ ✆ ✔

An Introduction to Type Theory – p.28/32

slide-146
SLIDE 146

Codes and data

data where

✁ ✄ ✗ ✛ ✝ ✄ ✁
✠ ✄ ✆ ✁
✒ ✁ ✠ ✆ ✁
✠ ✄ ✆ ✁
✜ ✗ ✁ ✠ ✆ ✁
☎ ✑ ✙ ✁

data

✠ ✁

where

✁ ✁ ✌
✁ ✄ ✂ ✒ ✝ ✁ ✁ ✁ ✁ ✌
✛ ✝ ✄
✁ ✁ ✌
✁ ✁ ✁ ✁ ✌
✝ ☎
✁ ✁ ✁ ✌
✒ ✁ ✠ ✆ ✔
✁ ✁ ✌ ✠ ✝ ✛ ✌
✁ ✁ ✌ ✓ ✜ ✗ ✁ ✠ ✆ ✔ ✁ ✁ ✁ ✁ ✌ ✆ ✝ ✛ ☎ ✁ ✁ ✁ ✁ ✌ ✓ ✜ ✗ ✁ ✠ ✆ ✔

An Introduction to Type Theory – p.28/32

slide-147
SLIDE 147

Codes and data

data where

✁ ✄ ✗ ✛ ✝ ✄ ✁
✠ ✄ ✆ ✁
✒ ✁ ✠ ✆ ✁
✠ ✄ ✆ ✁
✜ ✗ ✁ ✠ ✆ ✁
☎ ✑ ✙ ✁

data

✠ ✁

where

✁ ✁ ✌
✁ ✄ ✂ ✒ ✝ ✁ ✁ ✁ ✁ ✌
✛ ✝ ✄
✁ ✁ ✌
✁ ✁ ✁ ✁ ✌
✝ ☎
✁ ✁ ✁ ✌
✒ ✁ ✠ ✆ ✔
✁ ✁ ✌ ✠ ✝ ✛ ✌
✁ ✁ ✌ ✓ ✜ ✗ ✁ ✠ ✆ ✔ ✁ ✁ ✁ ✁ ✌ ✆ ✝ ✛ ☎ ✁ ✁ ✁ ✁ ✌ ✓ ✜ ✗ ✁ ✠ ✆ ✔
✁ ✁ ✌
✁ ✁ ✌
  • An Introduction to Type Theory – p.28/32
slide-148
SLIDE 148

Example

An Introduction to Type Theory – p.29/32

slide-149
SLIDE 149

Example

let

✄ ✄
✁ ✂ ✄ ✄
✁ ✂ ✄ ☞ ✌
✄ ✄ ✄

An Introduction to Type Theory – p.29/32

slide-150
SLIDE 150

Example

let

✄ ✄
✁ ✂ ✄ ✄
✁ ✂ ✄ ☞ ✌
✄ ✄ ✄

let

✁ ✄
✁ ☞ ✌ ✟ ✁ ✁ ✁
✁ ✁

An Introduction to Type Theory – p.29/32

slide-151
SLIDE 151

Example

let

✄ ✄
✁ ✂ ✄ ✄
✁ ✂ ✄ ☞ ✌
✄ ✄ ✄

let

✁ ✄
✁ ☞ ✌ ✟ ✁ ✁ ✁
✁ ✁

let

✂ ✄
✁ ✂
✂ ☞ ✌ ✞
✁ ✂ ✞
  • An Introduction to Type Theory – p.29/32
slide-152
SLIDE 152

Example

let

✄ ✄
✁ ✂ ✄ ✄
✁ ✂ ✄ ☞ ✌
✄ ✄ ✄

let

✁ ✄
✁ ☞ ✌ ✟ ✁ ✁ ✁
✁ ✁

let

✂ ✄
✁ ✂
✂ ☞ ✌ ✞
✁ ✂ ✞
  • let
✡ ✄
✁ ✂
✁ ✟ ✁ ✁ ✁ ✡ ✄
✁ ✂
✁ ✟ ✁ ✁ ✁ ✡ ☞ ✌ ✞

An Introduction to Type Theory – p.29/32

slide-153
SLIDE 153

Generic equality

An Introduction to Type Theory – p.30/32

slide-154
SLIDE 154

Generic equality

let

✂ ✄
✄ ✁ ✄
✂ ✂ ✂ ✄

An Introduction to Type Theory – p.30/32

slide-155
SLIDE 155

Generic equality

let

✂ ✄
✄ ✁ ✄
✂ ✂ ✂ ✄
✂ ✞
✂ ✞
✌ ✁ ✁ ✁
✞ ✁ ✂
✞ ✁ ✂ ✂
✆ ☞ ✌
✂ ✂ ✆ ✁ ✁
✂ ✆
✂ ✂ ✆ ☞ ✌
✂ ✂
✂ ✆
☞ ✌ ✂ ✂ ✄ ✟
✂ ✆ ☞ ✌ ✂ ✂ ✄ ✟
✆ ☞ ✌
✂ ✆ ☞ ✌
✂ ✂

An Introduction to Type Theory – p.30/32

slide-156
SLIDE 156

Advantages of Dependently Typed Programming

An Introduction to Type Theory – p.31/32

slide-157
SLIDE 157

Advantages of Dependently Typed Programming

Avoidance of run-time errors

An Introduction to Type Theory – p.31/32

slide-158
SLIDE 158

Advantages of Dependently Typed Programming

Avoidance of run-time errors More efficient code (elimination of tags)

An Introduction to Type Theory – p.31/32

slide-159
SLIDE 159

Advantages of Dependently Typed Programming

Avoidance of run-time errors More efficient code (elimination of tags) Extensions of Type System as library

An Introduction to Type Theory – p.31/32

slide-160
SLIDE 160

Advantages of Dependently Typed Programming

Avoidance of run-time errors More efficient code (elimination of tags) Extensions of Type System as library Easier to reason about

An Introduction to Type Theory – p.31/32

slide-161
SLIDE 161

Important issues

An Introduction to Type Theory – p.32/32

slide-162
SLIDE 162

Important issues

Definitional equality should be well behaved

An Introduction to Type Theory – p.32/32

slide-163
SLIDE 163

Important issues

Definitional equality should be well behaved Inductive families have to be supported

An Introduction to Type Theory – p.32/32

slide-164
SLIDE 164

Important issues

Definitional equality should be well behaved Inductive families have to be supported Type inference is generalized by elaboration Extensible elaboration ?

An Introduction to Type Theory – p.32/32

slide-165
SLIDE 165

Important issues

Definitional equality should be well behaved Inductive families have to be supported Type inference is generalized by elaboration Extensible elaboration ? Programs are constructed interactively, starting with the type as a partial specification

An Introduction to Type Theory – p.32/32