faith evolution and programming languages
play

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


  1. Faith, Evolution, and Programming Languages Philip Wadler University of Edinburgh

  2. Evolution

  3. Multiculturalism

  4. Part I Church: The origins of faith

  5. Gerhard Gentzen (1909–1945)

  6. Gerhard Gentzen (1935) — Natural Deduction

  7. Gerhard Gentzen (1935) — Natural Deduction

  8. Gerhard Gentzen (1935) — Natural Deduction [ A ] x · · A ⊃ B A ⊃ -E · B B ⊃ -I x A ⊃ B B & -I A & B & -E 0 A & B & -E 1 A A & B A B

  9. Simplifying a proof [ B & A ] z [ B & A ] z & -E 1 & -E 0 B & -I A A & B [ B ] y [ A ] x ⊃ -I z & -I ( B & A ) ⊃ ( A & B ) B & A ⊃ -E A & B

  10. Simplifying a proof [ B & A ] z [ B & A ] z & -E 1 & -E 0 B & -I A A & B [ B ] y [ A ] x ⊃ -I z & -I ( B & A ) ⊃ ( A & B ) B & A ⊃ -E A & B ⇓ [ B ] y [ A ] x [ B ] y [ A ] x & -I & -I B & A & -E 1 B & A & -E 0 B & -I A A & B

  11. Simplifying a proof [ B & A ] z [ B & A ] z & -E 1 & -E 0 B & -I A A & B [ B ] y [ A ] x ⊃ -I z & -I ( B & A ) ⊃ ( A & B ) B & A ⊃ -E A & B ⇓ [ B ] y [ A ] x [ B ] y [ A ] x & -I & -I B & A & -E 1 B & A & -E 0 B & -I A A & B ⇓ [ A ] x [ B ] y & -I A & B

  12. Alonzo Church (1903–1995)

  13. Alonzo Church (1932) — Lambda calculus

  14. Alonzo Church (1940) — Typed λ -calculus [ x : A ] x · s : A ⊃ B t : A ⊃ -E · · u : B s t : B ⊃ -I x λx. u : A ⊃ B t : A u : B & -I s : A & B & -E 0 s : A & B & -E 1 � t, u � : A & B s 0 : A s 1 : B

  15. Simplifying a program [ z : B & A ] z [ z : B & A ] z & -E 1 & -E 0 z 1 : A z 0 : B & -I � z 1 , z 0 � : A & B [ y : B ] y [ x : A ] x ⊃ -I z & -I λz. � z 1 , z 0 � : ( B & A ) ⊃ ( A & B ) � y, x � : B & A ⊃ -E ( λz. � z 1 , z 0 � ) � y, x � : A & B

  16. Simplifying a program [ z : B & A ] z [ z : B & A ] z & -E 1 & -E 0 z 1 : A z 0 : B & -I � z 1 , z 0 � : A & B [ y : B ] y [ x : A ] x ⊃ -I z & -I λz. � z 1 , z 0 � : ( B & A ) ⊃ ( A & B ) � y, x � : B & A ⊃ -E ( λz. � z 1 , z 0 � ) � y, x � : A & B ⇓ [ y : B ] y [ x : A ] x [ y : B ] y [ x : A ] x & -I & -I � y, x � : B & A & -E 1 � y, x � : B & A & -E 0 � y, x � 1 : A � y, x � 0 : B & -I �� y, x � 1 , � y, x � 0 � : A & B

  17. Simplifying a program [ z : B & A ] z [ z : B & A ] z & -E 1 & -E 0 z 1 : A z 0 : B & -I � z 1 , z 0 � : A & B [ y : B ] y [ x : A ] x ⊃ -I z & -I λz. � z 1 , z 0 � : ( B & A ) ⊃ ( A & B ) � y, x � : B & A ⊃ -E ( λz. � z 1 , z 0 � ) � y, x � : A & B ⇓ [ y : B ] y [ x : A ] x [ y : B ] y [ x : A ] x & -I & -I � y, x � : B & A & -E 1 � y, x � : B & A & -E 0 � y, x � 1 : A � y, x � 0 : B & -I �� y, x � 1 , � y, x � 0 � : A & B ⇓ [ x : A ] x [ y : B ] y & -I � x, y � : A & B

  18. William Howard (1980) — Curry-Howard Isomorphism

  19. Curry-Howard Hindley-Milner Girard-Reynolds

  20. Part II Second-order logic, Polymorphism, and Java

  21. Gottlob Frege (1879) — Quantifiers ( ∀ )

  22. John Reynolds (1974) — Polymorphism

  23. A magic trick r :: [ a ] → [ a ]

  24. Theorems for Free! [ a ] [ b ] r a ✲ r r map f map f ❄ ✲❄ r r r b [ a ] [ b ]

  25. Theorems for Free! [97 , 98 , 99] reverseInt [99 , 98 , 97] ✲ r r map chr map chr ❄ ✲❄ r r reverseChar [‘ a ′ , ‘ b ′ , ‘ c ′ ] [‘ c ′ , ‘ b ′ , ‘ a ′ ]

  26. Odersky and Wadler (1997) — Pizza

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

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

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

  30. Naftalin and Wadler (2006)

  31. Part III Haskell: Type Classes

  32. 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’

  33. Translation data Ord a = Ord { less :: a -> a -> Bool } ordInt :: Ord Int ordInt = Ord { less = primitiveLessInt } ordChar :: Ord Char ordChar = 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’

  34. Object-oriented

  35. Type classes

  36. 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]]

  37. Translation, continued ordList :: Ord a -> Ord [a] ordList 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)

  38. 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

  39. Part IV Three recent ideas

  40. Idea I: Blame calculus

  41. Idea II: Propositions as Sessions

  42. Idea III: Object to Object • Object vitiates parametricity class Object { Bool eq(Object that) {...} String show() {...} } • Top preserves parametricty class Object { // no methods! }

  43. Part V Aliens

  44. How to talk to aliens

  45. Independence Day

  46. A universal programming language?

  47. Lambda is Omniversal

Recommend


More recommend