https://www.youtube.com/watch?v=wTP2RUD_cL0 Theorems for Free Blame - - PowerPoint PPT Presentation

https youtube com watch v wtp2rud cl0 theorems for free
SMART_READER_LITE
LIVE PREVIEW

https://www.youtube.com/watch?v=wTP2RUD_cL0 Theorems for Free Blame - - PowerPoint PPT Presentation

https://www.youtube.com/watch?v=wTP2RUD_cL0 Theorems for Free Blame for All Philip Wadler University of Edinburgh QCon S ao Paulo 25 April 2017 Part I Theorems for Free A magic trick r :: a . [ a ] [ a ] :: a b . ( a b


slide-1
SLIDE 1

https://www.youtube.com/watch?v=wTP2RUD_cL0

slide-2
SLIDE 2

Theorems for Free Blame for All

Philip Wadler University of Edinburgh QCon S˜ ao Paulo 25 April 2017

slide-3
SLIDE 3

Part I

Theorems for Free

slide-4
SLIDE 4

A magic trick

slide-5
SLIDE 5

r :: ∀a. [a] → [a]

slide-6
SLIDE 6

map :: ∀a b. (a → b) → ([a] → [b]) f :: A → B map f :: [A] → [B]

slide-7
SLIDE 7

A [A] [A] B [B] [B] f r map f map f r

slide-8
SLIDE 8

reverse :: ∀a. [a] → [a]

slide-9
SLIDE 9

map :: ∀a b. (a → b) → ([a] → [b]) chr :: Int → Char map f :: [Int] → [Char]

slide-10
SLIDE 10

Int [Int] [Int] Char [Char] [Char] chr reverse map chr map chr reverse

slide-11
SLIDE 11

[97, 98, 99] [99, 98, 97] Int [Int] [Int] Char [Char] [Char] [‘a’, ‘b’, ‘c’] [‘c’, ‘b’, ‘a’] chr reverse map chr map chr reverse

slide-12
SLIDE 12

drop :: ∀a. Int → ([a] → [a]) drop 1 :: ∀a. [a] → [a]

slide-13
SLIDE 13

Int [Int] [Int] Int [Int] [Int] inc drop 1 map inc map inc drop 1

slide-14
SLIDE 14

[1, 2, 3] [2, 3] Int [Int] [Int] Int [Int] [Int] [2, 3, 4] [3, 4] inc drop 1 map inc map inc drop 1

slide-15
SLIDE 15

filter :: ∀a. (a → Bool) → ([a] → [a])

  • dd

:: Int → Bool filter odd :: [Int] → [Int]

slide-16
SLIDE 16

Int [Int] [Int] Int [Int] [Int] inc filter odd map inc map inc filter odd

slide-17
SLIDE 17

[1, 2, 3] [1, 3] Int [Int] [Int] Int [Int] [Int] [2, 3, 4] [3] = [2, 4] inc filter odd map inc map inc filter odd

slide-18
SLIDE 18

filter :: ∀a. (a → Bool) → ([a] → [a])

slide-19
SLIDE 19

A Bool [A] [A] B Bool [B] [B] p f id filter p map f map f q filter q

slide-20
SLIDE 20

Int Bool [Int] [Int] Int Bool [Int] [Int]

  • dd

inc id filter odd map inc map inc even filter even

slide-21
SLIDE 21

1 True [1, 2, 3] [1, 3] Int Bool [Int] [Int] Int Bool [Int] [Int] 2 True [2, 3, 4] [2, 4]

  • dd

inc id filter odd map inc map inc even filter even

slide-22
SLIDE 22
slide-23
SLIDE 23
slide-24
SLIDE 24

Part II

And now a word from our sponsor

slide-25
SLIDE 25

Lambda Calculus L, M, N ::= x | λx. N | L M Polymorphic Lambda Calculus A, B, C ::= X | A → B | ∀X. B L, M, N ::= x | λx:A. N | L M | ΛX. N | L A

slide-26
SLIDE 26

Part III

Blame for All

slide-27
SLIDE 27

A simple typed program

inc :: Int → Int inc x = x + 1 twice :: ∀a. (a → a) → (a → a) twice f x = f (f x) main :: Int main = twice inc 40 − → 42 : Int

slide-28
SLIDE 28

A simple untyped program

inc⋆ :: ⋆ inc⋆ x = x + 1 twice⋆ :: ⋆ twice⋆ f x = f (f x) main⋆ :: ⋆ main⋆ = twice⋆ inc⋆ 40 − → 42 : ⋆

slide-29
SLIDE 29

A simple untyped program

inc⋆ :: ⋆ inc⋆ x = x + 1 twice⋆ :: ⋆ twice⋆ f x = f (f x) main⋆ :: ⋆ main⋆ = twice⋆ inc⋆ 40 − → 42 : ⋆ Untyped is unityped

slide-30
SLIDE 30

Widening: casting from typed to untyped

inc⋆ :: ⋆ inc⋆ x = x + 1 twice :: ∀a. (a → a) → (a → a) twice f x = f (f x) twice⋆ :: ⋆ twice⋆ = twicep main :: ⋆ main = twice⋆ inc⋆ 40 − → 42 : ⋆

slide-31
SLIDE 31

Widening: casting from typed to untyped

inc⋆ :: ⋆ inc⋆ x = x + 1 twice :: ∀a. (a → a) → (a → a) twice f x = f (f x) twice⋆ :: ⋆ twice = twicep main :: ⋆ main = twice⋆ 40 inc⋆ − → blame p A cast from more-precise to less-precise type may blame the context containing the cast, but never the term contained in the cast.

slide-32
SLIDE 32

Narrowing: casting from untyped to typed

inc :: Int → Int inc x = x + 1 twice⋆ :: ⋆ twice⋆ f x = f (f x) twice :: ∀a. (a → a) → (a → a) twice = twice⋆p main :: Int main = twice inc 40 − → 42 : Int

slide-33
SLIDE 33

Narrowing: casting from untyped to typed

inc :: Int → Int inc x = x + 1 twice⋆ :: ⋆ twice⋆ f x = 42 twice :: ∀a. (a → a) → (a → a) twice = twice⋆p main :: Int main = twice inc 40 − → blame p A cast from less-precise to more-precise type may blame the term contained in the cast, but never the context containing the cast.

slide-34
SLIDE 34

Polymorphic Blame Calculus

slide-35
SLIDE 35
slide-36
SLIDE 36
slide-37
SLIDE 37
slide-38
SLIDE 38
slide-39
SLIDE 39

Part IV

Further Reading

slide-40
SLIDE 40

Theorems for Free Wadler; ICFP, 1989 Blame for All Ahmed, Findler, Siek, Wadler; POPL, 2011 Theorems for Free for Free Ahmed, Jamner, Siek, Wadler; ICFP, 2017 Mixed Messages Williams, Morris, Wadler, Zalewski; ECOOP, 2017 Propositions as Types Wadler; CACM, December 2015