Stop thinking about bottoms when writing programs . . . Thorsten - - PowerPoint PPT Presentation

stop thinking about bottoms when writing programs
SMART_READER_LITE
LIVE PREVIEW

Stop thinking about bottoms when writing programs . . . Thorsten - - PowerPoint PPT Presentation

Stop thinking about bottoms when writing programs . . . Thorsten Altenkirch University of Nottingham BCTCS 06 p.1/19 Trouble with BCTCS 06 p.2/19


slide-1
SLIDE 1

Stop thinking about bottoms when writing programs . . .

Thorsten Altenkirch University of Nottingham

BCTCS 06 – p.1/19

slide-2
SLIDE 2

Trouble with

BCTCS 06 – p.2/19

slide-3
SLIDE 3

Trouble with

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

BCTCS 06 – p.2/19

slide-4
SLIDE 4

Trouble with

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

BCTCS 06 – p.2/19

slide-5
SLIDE 5

Trouble with

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

No, because

✝ ✁ ✏ ✟ ✝ ✏ ✁ ✝ ✟ ✏

BCTCS 06 – p.2/19

slide-6
SLIDE 6

Trouble with . . .

BCTCS 06 – p.3/19

slide-7
SLIDE 7

Trouble with . . .

Many useful algebraic properties do not hold.

BCTCS 06 – p.3/19

slide-8
SLIDE 8

Trouble with . . .

Many useful algebraic properties do not hold.

Correctness proofs get obliterated with reasoning about

.

BCTCS 06 – p.3/19

slide-9
SLIDE 9

Trouble with . . .

Many useful algebraic properties do not hold.

Correctness proofs get obliterated with reasoning about

.

Do we actually care about non-terminating programs?

BCTCS 06 – p.3/19

slide-10
SLIDE 10

Trouble with . . .

Many useful algebraic properties do not hold.

Correctness proofs get obliterated with reasoning about

.

Do we actually care about non-terminating programs?

Programs are not natural phenomena. . .

BCTCS 06 – p.3/19

slide-11
SLIDE 11

Trouble with . . .

Many useful algebraic properties do not hold.

Correctness proofs get obliterated with reasoning about

.

Do we actually care about non-terminating programs?

Programs are not natural phenomena. . .

Programs are constructed!

BCTCS 06 – p.3/19

slide-12
SLIDE 12

Do we need to be lazy?

BCTCS 06 – p.4/19

slide-13
SLIDE 13

Do we need to be lazy?

✒✔✓✕ ✠ ✄ ✄ ☎ ✆ ✖ ☎ ✗ ✒✔✓✕ ✠ ✞ ✟ ✞ ✄
✓ ✕ ✠
☛ ☞ ✂ ✂

BCTCS 06 – p.4/19

slide-14
SLIDE 14

Do we need to be lazy?

✒✔✓✕ ✠ ✄ ✄ ☎ ✆ ✖ ☎ ✗ ✒✔✓✕ ✠ ✞ ✟ ✞ ✄
✓ ✕ ✠
☛ ☞ ✂ ✂ ✑ ✒✔✓✕ ✠

is total, if we interpret lists as a terminal coalgebra.

✖ ✘ ✗ ✟ ✙ ✚✜✛ ☞ ☛ ✘ ✢ ✚

BCTCS 06 – p.4/19

slide-15
SLIDE 15

data vs codata

BCTCS 06 – p.5/19

slide-16
SLIDE 16

data vs codata

✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✄ ✄ ✖✡✩ ✗ ✆ ✪✬✫ ✫ ✭ ✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✖ ✗ ✟ ✮✰✯✱ ✲ ✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★
✄ ✩✳ ✂ ✟ ✴
✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✞ ✂

BCTCS 06 – p.5/19

slide-17
SLIDE 17

data vs codata

✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✄ ✄ ✖✡✩ ✗ ✆ ✪✬✫ ✫ ✭ ✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✖ ✗ ✟ ✮✰✯✱ ✲ ✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★
✄ ✩✳ ✂ ✟ ✴
✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✞ ✂ ✑ ✣ ✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★

is total, . . .

BCTCS 06 – p.5/19

slide-18
SLIDE 18

data vs codata

✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✄ ✄ ✖✡✩ ✗ ✆ ✪✬✫ ✫ ✭ ✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✖ ✗ ✟ ✮✰✯✱ ✲ ✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★
✄ ✩✳ ✂ ✟ ✴
✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✞ ✂ ✑ ✣ ✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★

is total, . . .

if we interpret lists as initial algebra:

✖ ✘ ✗ ✟ ✵ ✚✜✛ ☞ ☛ ✘ ✢ ✚

BCTCS 06 – p.5/19

slide-19
SLIDE 19

data vs codata

✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✄ ✄ ✖✡✩ ✗ ✆ ✪✬✫ ✫ ✭ ✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✖ ✗ ✟ ✮✰✯✱ ✲ ✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★
✄ ✩✳ ✂ ✟ ✴
✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✞ ✂ ✑ ✣ ✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★

is total, . . .

if we interpret lists as initial algebra:

✖ ✘ ✗ ✟ ✵ ✚✜✛ ☞ ☛ ✘ ✢ ✚ ✑

Problem:

✣ ✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★
✓ ✕ ✠ ✝ ✂ ✟ ✏

BCTCS 06 – p.5/19

slide-20
SLIDE 20

data vs codata

BCTCS 06 – p.6/19

slide-21
SLIDE 21

data vs codata

Finite lists

✶✰✷ ✸ ✷ ✖✡✩ ✗ ✟ ✖ ✗✹ ✩ ✄ ✖ ✩ ✗

BCTCS 06 – p.6/19

slide-22
SLIDE 22

data vs codata

Finite lists

✶✰✷ ✸ ✷ ✖✡✩ ✗ ✟ ✖ ✗✹ ✩ ✄ ✖ ✩ ✗ ✑

Potentially infinite lists:

✺ ✫ ✶✰✷ ✸ ✷ ✖✡✻ ✗ ✼ ✩ ✟ ✖ ✗✹ ✩ ✄ ✖ ✻ ✗ ✼

BCTCS 06 – p.6/19

slide-23
SLIDE 23

data vs codata

Finite lists

✶✰✷ ✸ ✷ ✖✡✩ ✗ ✟ ✖ ✗✹ ✩ ✄ ✖ ✩ ✗ ✑

Potentially infinite lists:

✺ ✫ ✶✰✷ ✸ ✷ ✖✡✻ ✗ ✼ ✩ ✟ ✖ ✗✹ ✩ ✄ ✖ ✻ ✗ ✼ ✑

Better types

✒✔✓✕ ✠ ✄ ✄ ☎ ✆ ✖ ✻ ✗ ✼ ✣ ✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✄ ✄ ✖ ✩ ✗ ✆ ✪ ✫ ✫ ✭

BCTCS 06 – p.6/19

slide-24
SLIDE 24

data vs codata

Finite lists

✶✰✷ ✸ ✷ ✖✡✩ ✗ ✟ ✖ ✗✹ ✩ ✄ ✖ ✩ ✗ ✑

Potentially infinite lists:

✺ ✫ ✶✰✷ ✸ ✷ ✖✡✻ ✗ ✼ ✩ ✟ ✖ ✗✹ ✩ ✄ ✖ ✻ ✗ ✼ ✑

Better types

✒✔✓✕ ✠ ✄ ✄ ☎ ✆ ✖ ✻ ✗ ✼ ✣ ✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✄ ✄ ✖ ✩ ✗ ✆ ✪ ✫ ✫ ✭ ✑ ✣ ✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★
✓✕ ✠ ✝ ✂

doesn’t typecheck.

BCTCS 06 – p.6/19

slide-25
SLIDE 25

Can we always avoid ?

BCTCS 06 – p.7/19

slide-26
SLIDE 26

Can we always avoid ?

✶✰✷ ✸ ✷ ✽ ✾ ✟ ✿ ✹ ❀ ✹ ✽ ✾ ✄ ❁ ✽ ✾ ✞ ✒ ✄ ✄ ✽ ✾ ✆ ✽ ✾ ✞ ✒ ✿ ✟ ✿ ✞ ✒ ❀ ✟ ❀ ✞ ✒
✄ ❁✔❂ ✂ ✟
✒ ✧ ✂ ❁
✒ ❂ ✂
✂ ✄ ✄ ✽ ✾ ✆ ✽ ✾ ✆ ✽ ✾ ❀ ❁ ✧ ✟ ❀ ✄ ❁ ✧
✄ ❁ ✧ ✂ ❁ ❂ ✟ ✧ ✿ ❁ ✧ ✟ ✿ ✄ ❁ ✧
✄ ❁ ✧ ✂ ❁ ❂ ✟
✄ ❁ ✧ ✂ ✄ ❁ ❂
✄ ❁ ✧ ✂ ✄ ❁ ❂ ✂ ❁ ✤ ✟
❁ ✤ ✂ ❁
❁ ✤ ✂

BCTCS 06 – p.7/19

slide-27
SLIDE 27

Computational Reals

BCTCS 06 – p.8/19

slide-28
SLIDE 28

Computational Reals

Define computational reals (

) using Cauchy sequences.

BCTCS 06 – p.8/19

slide-29
SLIDE 29

Computational Reals

Define computational reals (

) using Cauchy sequences.

We cannot implement

❄ ✕ ✳ ✄ ✄ ❃ ✆ ✪✬✫ ✫ ✭

BCTCS 06 – p.8/19

slide-30
SLIDE 30

Computational Reals

Define computational reals (

) using Cauchy sequences.

We cannot implement

❄ ✕ ✳ ✄ ✄ ❃ ✆ ✪✬✫ ✫ ✭ ✑

Indeed, all total computable functions of type

❃ ✆ ✪✬✫ ✫ ✭

are constant (Brouwer).

BCTCS 06 – p.8/19

slide-31
SLIDE 31

Computational Reals

Define computational reals (

) using Cauchy sequences.

We cannot implement

❄ ✕ ✳ ✄ ✄ ❃ ✆ ✪✬✫ ✫ ✭ ✑

Indeed, all total computable functions of type

❃ ✆ ✪✬✫ ✫ ✭

are constant (Brouwer).

However, there are perfectly reasonable partial implementations

  • f
❄ ✕ ✳

.

BCTCS 06 – p.8/19

slide-32
SLIDE 32

We need for:

BCTCS 06 – p.9/19

slide-33
SLIDE 33

We need for:

Interpreters.

BCTCS 06 – p.9/19

slide-34
SLIDE 34

We need for:

Interpreters.

Functions on

.

BCTCS 06 – p.9/19

slide-35
SLIDE 35

We need for:

Interpreters.

Functions on

.

more examples ?

BCTCS 06 – p.9/19

slide-36
SLIDE 36

Epigram

BCTCS 06 – p.10/19

slide-37
SLIDE 37

Epigram

Epigram is a dependently typed programming language...

BCTCS 06 – p.10/19

slide-38
SLIDE 38

Epigram

Epigram is a dependently typed programming language...

All Epigram programs are total (i.e. no

).

BCTCS 06 – p.10/19

slide-39
SLIDE 39

Epigram

Epigram is a dependently typed programming language...

All Epigram programs are total (i.e. no

).

It is not a programming language in Peter Mosses sense.

BCTCS 06 – p.10/19

slide-40
SLIDE 40

Epigram

Epigram is a dependently typed programming language...

All Epigram programs are total (i.e. no

).

It is not a programming language in Peter Mosses sense.

because not all computable functions can be expressed.

BCTCS 06 – p.10/19

slide-41
SLIDE 41

Epigram

Epigram is a dependently typed programming language...

All Epigram programs are total (i.e. no

).

It is not a programming language in Peter Mosses sense.

because not all computable functions can be expressed.

I am going to show how we can fix this. . .

BCTCS 06 – p.10/19

slide-42
SLIDE 42

Epigram

Epigram is a dependently typed programming language...

All Epigram programs are total (i.e. no

).

It is not a programming language in Peter Mosses sense.

because not all computable functions can be expressed.

I am going to show how we can fix this. . .

without making Epigram partial.

BCTCS 06 – p.10/19

slide-43
SLIDE 43
  • Monads. . .

BCTCS 06 – p.11/19

slide-44
SLIDE 44
  • Monads. . .

A monad

✠ ✄ ✄ ✁ ✆ ✁

is given by

✓ ✣ ✧ ❂ ✓✞ ✄ ✄ ✩ ✆ ✠ ✩ ❆❅ ✂ ✄ ✄
✩ ✂ ✆
✆ ✠ ❇ ✂ ✆ ✠ ❇

subject to some equations.

BCTCS 06 – p.11/19

slide-45
SLIDE 45
  • Monads. . .

A monad

✠ ✄ ✄ ✁ ✆ ✁

is given by

✓ ✣ ✧ ❂ ✓✞ ✄ ✄ ✩ ✆ ✠ ✩ ❆❅ ✂ ✄ ✄
✩ ✂ ✆
✆ ✠ ❇ ✂ ✆ ✠ ❇

subject to some equations.

We can use monads to encapsulate effects (e.g. state)

✞ ✣❈ ❉ ❊ ❋ ✣ ✒ ✄ ✄ ✩ ✆
■ ❏ ❑ ✩ ✂ ✓ ✣ ✩ ▲ ❉ ❊ ❋ ✣ ✒ ✄ ✄
■ ❏ ❑ ✩ ✆
✩ ❈ ✓ ▼ ✧ ✣ ❉ ❊ ❋ ✣ ✒ ✄ ✄
■ ❏ ❑ ✩ ✆ ✩ ✆

BCTCS 06 – p.11/19

slide-46
SLIDE 46
  • Monads. . .

A monad

✠ ✄ ✄ ✁ ✆ ✁

is given by

✓ ✣ ✧ ❂ ✓✞ ✄ ✄ ✩ ✆ ✠ ✩ ❆❅ ✂ ✄ ✄
✩ ✂ ✆
✆ ✠ ❇ ✂ ✆ ✠ ❇

subject to some equations.

We can use monads to encapsulate effects (e.g. state)

✞ ✣❈ ❉ ❊ ❋ ✣ ✒ ✄ ✄ ✩ ✆
■ ❏ ❑ ✩ ✂ ✓ ✣ ✩ ▲ ❉ ❊ ❋ ✣ ✒ ✄ ✄
■ ❏ ❑ ✩ ✆
✩ ❈ ✓ ▼ ✧ ✣ ❉ ❊ ❋ ✣ ✒ ✄ ✄
■ ❏ ❑ ✩ ✆ ✩ ✆

and to model effects (e.g. state) :

✶✰✷ ✸ ✷ ✽ ◆ ✳ ✩ ✟ ❖
  • ✩◗P
✳ ✂ ✂ ❘❚❙ ❯ ✸ ✷ ❙ ✺ ❏ ❱ ✕ ✞ ✩ ▲
◆ ✳ ✂ ❲ ❳ ❏ ❨ ❏ ✓ ✣ ✧ ❂ ✓ ✞ ✩ ✟ ❖
✳ ✆
P ✳ ✂ ✂
◆ ✒ ✂❭❬ ❬ ✟ ✦ ✟ ❖
✳ ✆ ✭ ❏ ✸
P ✳ ❪ ✂ ✟ ✒ ✳ ❖ ✦ ❪ ✟ ✦ ✩ ❘❚❙ ✦ ❪ ✳ ❪ ✂

BCTCS 06 – p.11/19

slide-47
SLIDE 47

The Delay monad

BCTCS 06 – p.12/19

slide-48
SLIDE 48

The Delay monad

✺ ✫ ✶✰✷ ✸ ✷ ❫ ✩ ✟ ❴✰❵ ❛ ✩ ✹ ❜✰❝ ❞ ✲ ✯
✩ ✂

BCTCS 06 – p.12/19

slide-49
SLIDE 49

The Delay monad

✺ ✫ ✶✰✷ ✸ ✷ ❫ ✩ ✟ ❴✰❵ ❛ ✩ ✹ ❜✰❝ ❞ ✲ ✯
✩ ✂ ❘ ❙ ❯ ✸ ✷ ❙ ✺ ❏ ❱ ✕ ✞ ✩ ▲ ❫ ❲ ❳ ❏ ❨ ❏ ✓ ✣ ✧ ❂ ✓✞ ✟ ❴ ❵ ❛ ❴ ❵ ❛ ✩ ❬ ❬ ✟ ❡ ✟ ❡ ✩ ❜ ❝ ❞ ✲ ✯ ▲ ❬ ❬ ✟ ❡ ✟ ❜✰❝ ❞ ✲ ✯
❬ ❬ ✟ ❡ ✂

BCTCS 06 – p.12/19

slide-50
SLIDE 50

The Delay monad

✺ ✫ ✶✰✷ ✸ ✷ ❫ ✩ ✟ ❴✰❵ ❛ ✩ ✹ ❜✰❝ ❞ ✲ ✯
✩ ✂ ❘ ❙ ❯ ✸ ✷ ❙ ✺ ❏ ❱ ✕ ✞ ✩ ▲ ❫ ❲ ❳ ❏ ❨ ❏ ✓ ✣ ✧ ❂ ✓✞ ✟ ❴ ❵ ❛ ❴ ❵ ❛ ✩ ❬ ❬ ✟ ❡ ✟ ❡ ✩ ❜ ❝ ❞ ✲ ✯ ▲ ❬ ❬ ✟ ❡ ✟ ❜✰❝ ❞ ✲ ✯
❬ ❬ ✟ ❡ ✂ ✏ ✄ ✄ ❫ ✩ ✏ ✟ ❜ ❝ ❞ ✲ ✯ ✏

BCTCS 06 – p.12/19

slide-51
SLIDE 51

Iteration with Delay

✓ ✣ ❄ ✄ ✄
✆ ❫
▼ ✧ ★ ✣ ✓ ❇ ✩ ✂ ✂ ✆ ✩ ✆ ❫ ❇ ✓ ✣ ❄ ❡ ✩ ✟ ❡ ✩ ❬ ❬ ✟ ❩ ❇ ✩ ✆ ✺ ✷ ❯ ❏ ❇ ✩ ✫ ❑ ❜ ✲ ❣ ❞ ❇ ✆ ❴ ❵ ❛ ❇ ❤ ✐❦❥ ❧ ❞ ✩ ✆ ❜✰❝ ❞ ✲ ✯
✣ ❄ ❡ ✩ ✂

BCTCS 06 – p.13/19

slide-52
SLIDE 52

Fixpoints with Delay

BCTCS 06 – p.14/19

slide-53
SLIDE 53

Fixpoints with Delay

✓ ✣♠ ✄ ✄
✆ ❫ ❇ ✂ ✆
✆ ❫ ❇ ✂ ✂ ✆ ✩ ✆ ❫ ❇

BCTCS 06 – p.14/19

slide-54
SLIDE 54

Fixpoints with Delay

✓ ✣♠ ✄ ✄
✆ ❫ ❇ ✂ ✆
✆ ❫ ❇ ✂ ✂ ✆ ✩ ✆ ❫ ❇ ✓ ✣♠ ♥ ✩ ✟ ✩ ❂ ♦
✆ ✏ ✂ ❲ ❳ ❏ ❨ ❏ ✩ ❂ ♦ ✄ ✄
✆ ❫ ❇ ✂ ✆ ❫ ❇ ✩ ❂ ♦ ❡ ✟ ✓ ✩ ♠ ✣
✩ ✂
❝ ❞ ✲ ✯
❂ ♦
❡ ✂ ✂ ✂

BCTCS 06 – p.14/19

slide-55
SLIDE 55

Fixpoints with Delay

✓ ✣♠ ✄ ✄
✆ ❫ ❇ ✂ ✆
✆ ❫ ❇ ✂ ✂ ✆ ✩ ✆ ❫ ❇ ✓ ✣♠ ♥ ✩ ✟ ✩ ❂ ♦
✆ ✏ ✂ ❲ ❳ ❏ ❨ ❏ ✩ ❂ ♦ ✄ ✄
✆ ❫ ❇ ✂ ✆ ❫ ❇ ✩ ❂ ♦ ❡ ✟ ✓ ✩ ♠ ✣
✩ ✂
❝ ❞ ✲ ✯
❂ ♦
❡ ✂ ✂ ✂ ✓ ✩ ♠ ✣ ✄ ✄
✩ ✂ ✆
✩ ✂ ✆
✩ ✂ ✓ ✩ ♠ ✣
❵ ❛ ✩ ✂ ✟ ❴ ❵ ❛ ✩ ✓ ✩ ♠ ✣
❝ ❞ ✲ ✯ ✂
❵ ❛ ✩ ✂ ✟ ❴ ❵ ❛ ✩ ✓ ✩ ♠ ✣
❝ ❞ ✲ ✯ ▲ ✂
❝ ❞ ✲ ✯ ▲ ❪ ✂ ✟ ❜ ❝ ❞ ✲ ✯
✩ ♠ ✣ ▲ ▲ ❪ ✂

BCTCS 06 – p.14/19

slide-56
SLIDE 56

From Delay to Partial

BCTCS 06 – p.15/19

slide-57
SLIDE 57

From Delay to Partial

✑ ❫

is too intensional. . .

BCTCS 06 – p.15/19

slide-58
SLIDE 58

From Delay to Partial

✑ ❫

is too intensional. . .

We can observe how fast a function terminates.

BCTCS 06 – p.15/19

slide-59
SLIDE 59

From Delay to Partial

✑ ❫

is too intensional. . .

We can observe how fast a function terminates.

Hence

✓ ✣♠ ✒ ♣ ✟ ✒
✣♠ ✒ ✂

BCTCS 06 – p.15/19

slide-60
SLIDE 60

From Delay to Partial

✑ ❫

is too intensional. . .

We can observe how fast a function terminates.

Hence

✓ ✣♠ ✒ ♣ ✟ ✒
✣♠ ✒ ✂ ✑

We define

q ✩ ✟ ❫ ✩ rts

where

s ✉ ❫ ✩ ✢ ❫ ✩

identifies values with different finite delay.

BCTCS 06 – p.15/19

slide-61
SLIDE 61

From Delay to Partial

✑ ❫

is too intensional. . .

We can observe how fast a function terminates.

Hence

✓ ✣♠ ✒ ♣ ✟ ✒
✣♠ ✒ ✂ ✑

We define

q ✩ ✟ ❫ ✩ rts

where

s ✉ ❫ ✩ ✢ ❫ ✩

identifies values with different finite delay.

We have to show that

❬ ❬ ✟

,

✓ ✣ ❄

,

✓ ✣♠

preserve

s

.

BCTCS 06 – p.15/19

slide-62
SLIDE 62

From Delay to Partial

✑ ❫

is too intensional. . .

We can observe how fast a function terminates.

Hence

✓ ✣♠ ✒ ♣ ✟ ✒
✣♠ ✒ ✂ ✑

We define

q ✩ ✟ ❫ ✩ rts

where

s ✉ ❫ ✩ ✢ ❫ ✩

identifies values with different finite delay.

We have to show that

❬ ❬ ✟

,

✓ ✣ ❄

,

✓ ✣♠

preserve

s

.

We have

✓ ✣♠ ✒ s ✒
✣♠ ✒ ✂

BCTCS 06 – p.15/19

slide-63
SLIDE 63

From Delay to Partial

✑ ❫

is too intensional. . .

We can observe how fast a function terminates.

Hence

✓ ✣♠ ✒ ♣ ✟ ✒
✣♠ ✒ ✂ ✑

We define

q ✩ ✟ ❫ ✩ rts

where

s ✉ ❫ ✩ ✢ ❫ ✩

identifies values with different finite delay.

We have to show that

❬ ❬ ✟

,

✓ ✣ ❄

,

✓ ✣♠

preserve

s

.

We have

✓ ✣♠ ✒ s ✒
✣♠ ✒ ✂

if

is

  • continuous,

however all definable

are.

BCTCS 06 – p.15/19

slide-64
SLIDE 64

Defining

BCTCS 06 – p.16/19

slide-65
SLIDE 65

Defining

① ✑
✂ ✉ ❫ ✩ ✢ ✻

is defined inductively.

❴✰❵ ❛ ✩ ② ✻ ③ ② ✻ ❜ ❝ ❞ ✲ ✯ ▲ ② ✻

BCTCS 06 – p.16/19

slide-66
SLIDE 66

Defining

① ✑
✂ ✉ ❫ ✩ ✢ ✻

is defined inductively.

❴✰❵ ❛ ✩ ② ✻ ③ ② ✻ ❜ ❝ ❞ ✲ ✯ ▲ ② ✻ ✑ ④ ✉ ❫ ✩ ✢ ❫ ✩ ③ ④ ③ ❪ ✟ ⑤ ✻ ✛ ③ ② ✻ ✟ ⑥ ③ ❪ ② ✻

BCTCS 06 – p.16/19

slide-67
SLIDE 67

Defining

① ✑
✂ ✉ ❫ ✩ ✢ ✻

is defined inductively.

❴✰❵ ❛ ✩ ② ✻ ③ ② ✻ ❜ ❝ ❞ ✲ ✯ ▲ ② ✻ ✑ ④ ✉ ❫ ✩ ✢ ❫ ✩ ③ ④ ③ ❪ ✟ ⑤ ✻ ✛ ③ ② ✻ ✟ ⑥ ③ ❪ ② ✻ ✑ s ✉ ❫ ✩ ✢ ❫ ✩ ③ s ③ ❪ ✟ ③ ④ ③ ❪⑧⑦ ③ ❪ ④ ③

BCTCS 06 – p.16/19

slide-68
SLIDE 68

Deja vu ?

BCTCS 06 – p.17/19

slide-69
SLIDE 69

Deja vu ?

Constructive Domain Theory!

BCTCS 06 – p.17/19

slide-70
SLIDE 70

Deja vu ?

Constructive Domain Theory!

✑ q ✩ ✟ ✻ ⑨

BCTCS 06 – p.17/19

slide-71
SLIDE 71

Deja vu ?

Constructive Domain Theory!

✑ q ✩ ✟ ✻ ⑨ ✑

Note that constructively

✻ ⑨ ♣ ✟ ✻ ☛ ⑩ ✏ ❶

because we cannot observe non-termination.

BCTCS 06 – p.17/19

slide-72
SLIDE 72

Deja vu ?

Constructive Domain Theory!

✑ q ✩ ✟ ✻ ⑨ ✑

Note that constructively

✻ ⑨ ♣ ✟ ✻ ☛ ⑩ ✏ ❶

because we cannot observe non-termination.

✑ q ✩

and hence

✩ ✆ q ❇

are

CPOs.

BCTCS 06 – p.17/19

slide-73
SLIDE 73

Deja vu ?

Constructive Domain Theory!

✑ q ✩ ✟ ✻ ⑨ ✑

Note that constructively

✻ ⑨ ♣ ✟ ✻ ☛ ⑩ ✏ ❶

because we cannot observe non-termination.

✑ q ✩

and hence

✩ ✆ q ❇

are

CPOs.

✑ ✓ ✣♠ ✒ ✟ ❷❹❸ ❺ ❻ ✇ ❸ ✏

the code before constructs

in

✩ ✆ q ❇

.

BCTCS 06 – p.17/19

slide-74
SLIDE 74

Conclusions and further work

BCTCS 06 – p.18/19

slide-75
SLIDE 75

Conclusions and further work

Using the partiality monad we can encapsulate partial programs in a total language.

BCTCS 06 – p.18/19

slide-76
SLIDE 76

Conclusions and further work

Using the partiality monad we can encapsulate partial programs in a total language.

Partiality is an effect

BCTCS 06 – p.18/19

slide-77
SLIDE 77

Conclusions and further work

Using the partiality monad we can encapsulate partial programs in a total language.

Partiality is an effect

We can reason about partial programs at compile time using the definition of

q ✩

.

BCTCS 06 – p.18/19

slide-78
SLIDE 78

Conclusions and further work

Using the partiality monad we can encapsulate partial programs in a total language.

Partiality is an effect

We can reason about partial programs at compile time using the definition of

q ✩

.

and we can execute non-terminating programs at run-time.

BCTCS 06 – p.18/19

slide-79
SLIDE 79

Conclusions and further work

Using the partiality monad we can encapsulate partial programs in a total language.

Partiality is an effect

We can reason about partial programs at compile time using the definition of

q ✩

.

and we can execute non-terminating programs at run-time.

In future Epigram could support partiality without giving up the advantages of having a total language for most programs.

BCTCS 06 – p.18/19

slide-80
SLIDE 80

Conclusions and further work

Using the partiality monad we can encapsulate partial programs in a total language.

Partiality is an effect

We can reason about partial programs at compile time using the definition of

q ✩

.

and we can execute non-terminating programs at run-time.

In future Epigram could support partiality without giving up the advantages of having a total language for most programs.

Still to do: recursive datatypes by a constructive implementation

  • f the standard domain-theoretic construction.

BCTCS 06 – p.18/19

slide-81
SLIDE 81

Thank you

Thanks to Conor McBride & the Epigram Team (James Chapman, Peter Morris, Wouter Swierstra) see www.e-pig.org for more information on Epigram.

Acknowledgements to Tarmo Uustalu and Venanzio Capretta for joint work on a partial paper. . .

Looking for my papers? Type “Thorsten” into google. . .

BCTCS 06 – p.19/19