Stop thinking about bottoms when writing programs . . . Thorsten Altenkirch University of Nottingham BCTCS 06 – p.1/19
Trouble with BCTCS 06 – p.2/19
✟ � ✁ ✠ ✟ ✞ ✁ ✂ ☞ ☛ ✞ ✝ ✞ ☛ ✁ ✝ ☎ ✆ ☎ ✆ ☎ ✄ ✄ ✂ ✁ ✞ Trouble with �✡✠ BCTCS 06 – p.2/19
BCTCS 06 – p.2/19 ✞ ✞ ✟ ✠ ✁ ✞ ☛ ✌ ✂ ✁ ✍ ✟ ✍ ✁ ✌ ✎ ✁ ☞ � ☎ ✁ ✂ ✄ ✄ ☎ ✆ ✆ ☛ ☎ ✝ ✁ ✞ ✟ ✝ Trouble with �✡✠
BCTCS 06 – p.2/19 ✎ ☛ ✞ ✌ ✁ ✍ ✟ ✍ ✁ ✌ ✝ � ✁ ✏ ✟ ✝ ✏ ✁ ✝ ✟ ✏ ✞ ✁ ✠ ✁ ✄ ☎ ✆ ☎ ✆ ☎ ✝ ✟ ✞ ✂ ✟ ✝ ✁ ☛ ☞ ✂ ✁ ✞ ✄ Trouble with No, because �✡✠
Trouble with . . . BCTCS 06 – p.3/19
✑ Trouble with . . . Many useful algebraic properties do not hold. BCTCS 06 – p.3/19
✑ ✑ ✏ Trouble with . . . Many useful algebraic properties do not hold. Correctness proofs get obliterated with reasoning about . BCTCS 06 – p.3/19
✑ ✑ ✏ ✑ 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
✑ ✑ ✏ ✑ ✑ 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
✑ ✑ ✏ ✑ ✑ ✑ 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
Do we need to be lazy? BCTCS 06 – p.4/19
✟ ✞ � ✠ ✕ ✓ ✒ � ✄ ✞ ☞ ✠ ☛ ✂ ✗ ☎ ✖ ✆ ☎ ✄ ✄ ✠ ✂ ✞ Do we need to be lazy? ✒✔✓✕ ✒✔✓✕ BCTCS 06 – p.4/19
� ✂ ✠ ✘ ✞ ☛ ☞ ✂ ✑ ✓ ☛ ✠ ☞ ✖ ✘ ✗ ✕ ✒ ✙ ✖ ✚ ✠ ✄ ✄ ☎ ✆ ☎ � ✗ ✢ ✠ ✞ ✟ ✞ ✄ ✟ Do we need to be lazy? ✒✔✓✕ ✒✔✓✕ is total, if we interpret lists as a terminal coalgebra. ✒✔✓✕ ✚✜✛ BCTCS 06 – p.4/19
data vs codata BCTCS 06 – p.5/19
✲ ✩ ✣✤ ✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ � ✄ ✟ ✩✳ ✂ ✟ ✴ � ✣ ✤ ✣ ✞ ✥ ✣ ✞ ★ ✗ ✧ ✗ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✄ ✄ ✂ ✆ ✖ ✞ ✫ ✭ ✣✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✦ data vs codata ✖✡✩ ✪✬✫ ✮✰✯✱ BCTCS 06 – p.5/19
BCTCS 06 – p.5/19 ✟ ✞ ✣ ✤ ✣ � ✴ ✂ ✣ ✩✳ ✄ ✩ � ★ ✧ ✥ ✞ ✣✤ ✞ ★ ✧ ✦ ✞ ✣ ✥ ✣ ✦ ✤ ✣ ✑ ✂ ✞ ★ ✧ ✦ ✞ ✣ ✥ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✄ ✄ ✗ ✆ ✫ ✭ ✣✤ ✣ ✞ ✞ ✣ ✣✤ ✲ ✟ ✗ ✖ ★ ✧ ✦ ✞ ✣ ✥ ✮✰✯✱ is total, . . . data vs codata ✪✬✫ ✖✡✩
BCTCS 06 – p.5/19 ✣ ✑ ✂ ✞ ★ ✧ ✦ ✞ ✥ ✤ ✞ ✣ ✤ ✣ � ✴ ✟ ✂ ✣ ✣ ✣✤ ✗ ✚ ✢ ✘ ☛ ☞ ✵ ✟ ✘ ✞ ✖ ✑ ★ ✧ ✦ ✞ ✣ ✥ ✩✳ ✄ ✩ ✄ ✣ ✣✤ ✭ ✫ ✆ ✗ ✄ ★ ✥ ✧ ✦ ✞ ✣ ✥ ✞ ✣ � ✞ ✣ ✦ ✞ ✣ ✣✤ ✲ ✞ ✞ ✧ ✣ ✟ ★ ✗ ✖ ★ ✧ ✦ ✥ if we interpret lists as initial algebra: ✚✜✛ ✮✰✯✱ is total, . . . data vs codata ✪✬✫ ✖✡✩
BCTCS 06 – p.5/19 ✥ ✟ ✗ ✘ ✖ ✑ ★ ✧ ✦ ✞ ✣ ✞ ☞ ✣ ✤ ✣ ✑ ✂ ✞ ★ ✧ ✦ ✞ ✵ ☛ ✥ ✧ ✏ ✟ ✂ ✝ ✠ ✕ ✓ ✒ � ★ ✦ ✘ ✞ ✣ ✥ ✞ ✣ ✤ ✣ ✑ ✚ ✢ ✣✤ ✣ ✞ ✞ ✖ ✣ ★ ✧ ✦ ✞ ✣ ✥ ✥ ✣ ✟ ✣✤ ✭ ✫ ✣ ✆ ✗ ✞ ✄ ✄ ★ ✗ ✞ ✦ � ✤ ✣ � ✴ ✟ ✂ ✩✳ ✄ ✩ ★ ✲ ✧ ✦ ✞ ✣ ✥ ✞ ✣ ✣ ✣✤ ✧ if we interpret lists as initial algebra: ✚✜✛ ✮✰✯✱ is total, . . . data vs codata ✪✬✫ ✖✡✩ Problem:
data vs codata BCTCS 06 – p.6/19
✟ ✄ ✗ ✩ ✸ ✷ ✖ ✗ ✑ ✖ ✗✹ ✩ data vs codata Finite lists ✖✡✩ ✶✰✷ BCTCS 06 – p.6/19
✺ ✗ ✟ ✩ ✼ ✗ ✩ ✷ ✸ ✄ ✫ ✑ ✖ ✑ ✩ ✗✹ ✖ ✄ ✩ ✗✹ ✖ ✟ ✗ ✻ ✷ ✸ ✗ ✼ ✖ data vs codata Finite lists ✖✡✩ ✶✰✷ Potentially infinite lists: ✖✡✻ ✶✰✷ BCTCS 06 – p.6/19
✗ ✖ ✖ ✻ ✑ ✼ ✑ ✩ ✖ ✠ ✄ ✄ ☎ ✆ ✻ ✩ ✗ ✼ ✣ ✤ ✣ ✞ ✥ ✣ ✞ ✦ ✧ ★ ✄ ✗✹ ✄ ✩ ✭ ✫ ✸ ✷ ✫ ✗ ✟ ✖ ✗✹ ✩ ✄ ✖ ✗ ✖ ✑ ✪ ✺ ✫ ✆ ✸ ✷ ✗ ✗ ✼ ✩ ✟ ✄ data vs codata Finite lists ✖✡✩ ✶✰✷ Potentially infinite lists: ✖✡✻ ✶✰✷ Better types ✒✔✓✕ BCTCS 06 – p.6/19
BCTCS 06 – p.6/19 ✦ ✗ ✩ ✖ ✄ ✄ ★ ✧ ✞ ✪ ✣ ✥ ✞ ✣ ✤ ✣ ✼ ✗ ✆ ✫ ✖ ✦ ✂ ✝ ✠ ✓✕ ✒ � ★ ✧ ✞ ✫ ✣ ✥ ✞ ✣ ✤ ✣ ✑ ✭ ✻ ✆ ✑ ✖ ☎ ✫ ✺ ✑ ✗ ✩ ✄ ✗ ✩ ✗✹ ✖ ✟ ✗ ✷ ✸ ✷ ✸ ✼ ✖ ✄ ✄ ✠ ✑ ✼ ✻ ✗ ✄ ✩ ✗✹ ✖ ✟ ✩ doesn’t typecheck. Potentially infinite lists: data vs codata ✖✡✻ ✖✡✩ Better types Finite lists ✶✰✷ ✒✔✓✕ ✶✰✷
Can we always avoid ? BCTCS 06 – p.7/19
BCTCS 06 – p.7/19 ❁ ❂ ❁ ✂ ✧ ❁ ✄ ✿ � ✧ ❁ ✄ ✿ ✟ ✧ ✿ � ❀ ✟ ❀ ✄ ❁ ✧ � ✄ ✧ ❁ ✧ ✂ ❁ ❂ ✟ ✟ ✿ ❁ ✂ ✂ ✤ ❁ ❂ � ❁ ✂ ✤ ❁ ✧ � ✟ ✤ ❁ ❂ ✄ � ❁ ✧ ✂ ✄ ❁ ❂ � ❁ ✿ ✄ ❁ ✧ ✂ ✄ ✧ ❀ ✟ ✄ ❀ ✒ ✞ ✿ ✟ ✿ ✒ ✞ ✾ ✽ ✆ ✾ ✽ ✄ ❀ ✒ ✞ ✾ ✽ ❁ ✄ ✾ ✽ ✹ ❀ ✹ ✿ ✟ ✾ ✾ ✞ ✷ ❂ ✽ ✆ ✾ ✽ ✆ ✾ ✽ ✄ ✄ ✂ ❁ � ✂ ✒ ✒ ✞ � ❁ ✂ ✧ ✒ ✞ � ✟ ✂ ✸ ✄ ✧ � ✽ ? Can we always avoid ❁✔❂ ✶✰✷
Computational Reals BCTCS 06 – p.8/19
✑ ❃ Computational Reals Define computational reals ( ) using Cauchy sequences. BCTCS 06 – p.8/19
✳ ❃ ✭ ❃ ✫ ✑ ✆ ❄ ✕ ✑ ✄ ✄ Computational Reals Define computational reals ( ) using Cauchy sequences. We cannot implement ✪✬✫ BCTCS 06 – p.8/19
✆ ✳ ✫ ❃ ✑ ❃ ✄ ✄ ✕ ✑ ❄ ✆ ✑ ✫ ❃ ✭ ✭ 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
✑ ✄ ❃ ✭ ✑ ✭ ✫ ✑ ✆ ❃ ✄ ✫ ✳ ✕ ❄ ❄ ✑ ✕ ❃ ✳ ✆ 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 of . BCTCS 06 – p.8/19
We need for: BCTCS 06 – p.9/19
✑ We need for: Interpreters. BCTCS 06 – p.9/19
✑ ✑ ❃ We need for: Interpreters. Functions on . BCTCS 06 – p.9/19
✑ ✑ ❃ ✑ We need for: Interpreters. Functions on . more examples ? BCTCS 06 – p.9/19
Epigram BCTCS 06 – p.10/19
✑ Epigram Epigram is a dependently typed programming language... BCTCS 06 – p.10/19
✑ ✑ ✏ Epigram Epigram is a dependently typed programming language... All Epigram programs are total (i.e. no ). BCTCS 06 – p.10/19
✑ ✑ ✏ ✑ 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
✑ ✑ ✏ ✑ ✑ 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
✑ ✑ ✏ ✑ ✑ ✑ 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
Recommend
More recommend