Faith, Evolution, and Programming Languages Philip Wadler - - PowerPoint PPT Presentation

faith evolution and programming languages
SMART_READER_LITE
LIVE PREVIEW

Faith, Evolution, and Programming Languages Philip Wadler - - PowerPoint PPT Presentation

Faith, Evolution, and Programming Languages Philip Wadler University of Edinburgh Evolution Multiculturalism Part I Church: The origins of faith Gerhard Gentzen (19091945) Gerhard Gentzen (1935) Natural Deduction Gerhard Gentzen


slide-1
SLIDE 1

Faith, Evolution, and Programming Languages

Philip Wadler University of Edinburgh

slide-2
SLIDE 2

Evolution

slide-3
SLIDE 3

Multiculturalism

slide-4
SLIDE 4

Part I

Church: The origins of faith

slide-5
SLIDE 5
slide-6
SLIDE 6
slide-7
SLIDE 7

Gerhard Gentzen (1909–1945)

slide-8
SLIDE 8

Gerhard Gentzen (1935) — Natural Deduction

slide-9
SLIDE 9

Gerhard Gentzen (1935) — Natural Deduction

slide-10
SLIDE 10

Gerhard Gentzen (1935) — Natural Deduction

[A]x · · · B ⊃-Ix A ⊃ B A ⊃ B A ⊃-E B A B &-I A & B A & B &-E0 A A & B &-E1 B

slide-11
SLIDE 11

Simplifying a proof

[B & A]z &-E1 A [B & A]z &-E0 B &-I A & B ⊃-Iz (B & A) ⊃ (A & B) [B]y [A]x &-I B & A ⊃-E A & B

slide-12
SLIDE 12

Simplifying a proof

[B & A]z &-E1 A [B & A]z &-E0 B &-I A & B ⊃-Iz (B & A) ⊃ (A & B) [B]y [A]x &-I B & A ⊃-E A & B ⇓ [B]y [A]x &-I B & A &-E1 A [B]y [A]x &-I B & A &-E0 B &-I A & B

slide-13
SLIDE 13

Simplifying a proof

[B & A]z &-E1 A [B & A]z &-E0 B &-I A & B ⊃-Iz (B & A) ⊃ (A & B) [B]y [A]x &-I B & A ⊃-E A & B ⇓ [B]y [A]x &-I B & A &-E1 A [B]y [A]x &-I B & A &-E0 B &-I A & B ⇓ [A]x [B]y &-I A & B

slide-14
SLIDE 14

Alonzo Church (1903–1995)

slide-15
SLIDE 15

Alonzo Church (1932) — Lambda calculus

slide-16
SLIDE 16

Alonzo Church (1940) — Typed λ-calculus

[x : A]x · · · u : B ⊃-Ix λx. u : A ⊃ B s : A ⊃ B t : A ⊃-E s t : B t : A u : B &-I t, u : A & B s : A & B &-E0 s0 : A s : A & B &-E1 s1 : B

slide-17
SLIDE 17

Simplifying a program

[z : B & A]z &-E1 z1 : A [z : B & A]z &-E0 z0 : B &-I z1, z0 : A & B ⊃-Iz λz. z1, z0 : (B & A) ⊃ (A & B) [y : B]y [x : A]x &-I y, x : B & A ⊃-E (λz. z1, z0) y, x : A & B

slide-18
SLIDE 18

Simplifying a program

[z : B & A]z &-E1 z1 : A [z : B & A]z &-E0 z0 : B &-I z1, z0 : A & B ⊃-Iz λz. z1, z0 : (B & A) ⊃ (A & B) [y : B]y [x : A]x &-I y, x : B & A ⊃-E (λz. z1, z0) y, x : A & B ⇓ [y : B]y [x : A]x &-I y, x : B & A &-E1 y, x1 : A [y : B]y [x : A]x &-I y, x : B & A &-E0 y, x0 : B &-I y, x1, y, x0 : A & B

slide-19
SLIDE 19

Simplifying a program

[z : B & A]z &-E1 z1 : A [z : B & A]z &-E0 z0 : B &-I z1, z0 : A & B ⊃-Iz λz. z1, z0 : (B & A) ⊃ (A & B) [y : B]y [x : A]x &-I y, x : B & A ⊃-E (λz. z1, z0) y, x : A & B ⇓ [y : B]y [x : A]x &-I y, x : B & A &-E1 y, x1 : A [y : B]y [x : A]x &-I y, x : B & A &-E0 y, x0 : B &-I y, x1, y, x0 : A & B ⇓ [x : A]x [y : B]y &-I x, y : A & B

slide-20
SLIDE 20

William Howard (1980) — Curry-Howard Isomorphism

slide-21
SLIDE 21

Curry-Howard Hindley-Milner Girard-Reynolds

slide-22
SLIDE 22

Part II

Second-order logic, Polymorphism, and Java

slide-23
SLIDE 23

Gottlob Frege (1879) — Quantifiers (∀)

slide-24
SLIDE 24

John Reynolds (1974) — Polymorphism

slide-25
SLIDE 25

A magic trick

r :: [a] → [a]

slide-26
SLIDE 26

Theorems for Free!

r r r r ✲ ❄ ✲❄

[a] map f [a] [b] map f [b] ra rb

slide-27
SLIDE 27

Theorems for Free!

r r r r ✲ ❄ ✲❄

[97, 98, 99] map chr [‘a′, ‘b′, ‘c′] [99, 98, 97] map chr [‘c′, ‘b′, ‘a′] reverseInt reverseChar

slide-28
SLIDE 28

Odersky and Wadler (1997) — Pizza

slide-29
SLIDE 29

Igarashi, Pierce, and Wadler (1999) — Featherweight Java

slide-30
SLIDE 30

Igarashi, Pierce, and Wadler (1999) — Featherweight Generic Java

slide-31
SLIDE 31

Gosling, Joy, Steele, Bracha (2004) — Java 5

slide-32
SLIDE 32

Naftalin and Wadler (2006)

slide-33
SLIDE 33

Part III

Haskell: Type Classes

slide-34
SLIDE 34

Type classes

class Ord a where (<) :: a -> a -> Bool instance Ord Int where (<) = primitiveLessInt instance Ord Char where (<) = primitiveLessChar max :: Ord a => a -> a -> a max x y | x < y = y | otherwise = x maximum :: Ord a => [a] -> a maximum [x] = x maximum (x:xs) = max x (maximum xs) maximum [0,1,2] == 2 maximum "abc" == ’c’

slide-35
SLIDE 35

Translation

data Ord a = Ord { less :: a -> a -> Bool }

  • rdInt :: Ord Int
  • rdInt =

Ord { less = primitiveLessInt }

  • rdChar :: Ord Char
  • rdChar =

Ord { less = primitiveLessChar } max :: Ord a -> a -> a -> a max d x y | less d x y = x | otherwise = y maximum :: Ord a -> [a] -> a maximum d [x] = x maximum d (x:xs) = max d x (maximum d xs) maximum ordInt [0,1,2] == 2 maximum ordChar "abc" == ’c’

slide-36
SLIDE 36

Object-oriented

slide-37
SLIDE 37

Type classes

slide-38
SLIDE 38

Type classes, continued

instance Ord a => Ord [a] where [] < [] = False [] < y:ys = True x:xs < [] = False x:xs < y:ys | x < y = True | y < x = False | otherwise = xs < ys maximum ["zero","one","two"] == "zero" maximum [[[0],[1]],[[0,1]]] == [[0,1]]

slide-39
SLIDE 39

Translation, continued

  • rdList :: Ord a -> Ord [a]
  • rdList d

= Ord { less = lt } where lt d [] [] = False lt d [] (y:ys) = True lt d (x:xs) [] = False lt d (x:xs) (y:ys) | less d x y = True | less d y x = False | otherwise = lt d xs ys maximum d0 ["zero","one","two"] == "zero" maximum d1 [[[0],[1]],[[0,1]]] == [[0,1]] where d0 = ordList ordChar d1 = ordList (ordList ordInt)

slide-40
SLIDE 40

Maximum of a list, in Java

public static <T extends Comparable<T>> T maximum(List<T> elts) { T candidate = elts.get(0); for (T elt : elts) { if (candidate.compareTo(elt) < 0) candidate = elt; } return candidate; } List<Integer> ints = Arrays.asList(0,1,2); assert maximum(ints) == 2; List<String> strs = Arrays.asList("zero","one","two"); assert maximum(strs).equals("zero"); List<Number> nums = Arrays.asList(0,1,2,3.14); assert maximum(nums) == 3.14; // compile-time error

slide-41
SLIDE 41

Part IV

Three recent ideas

slide-42
SLIDE 42

Idea I: Blame calculus

slide-43
SLIDE 43

Idea II: Propositions as Sessions

slide-44
SLIDE 44

Idea III: Object to Object

  • Object vitiates parametricity

class Object { Bool eq(Object that) {...} String show() {...} }

  • Top preserves parametricty

class Object { // no methods! }

slide-45
SLIDE 45

Part V

Aliens

slide-46
SLIDE 46

How to talk to aliens

slide-47
SLIDE 47

Independence Day

slide-48
SLIDE 48

A universal programming language?

slide-49
SLIDE 49

Lambda is Omniversal