Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Programming with Birds - There is a Bluebird in...

Programming with Birds - There is a Bluebird in My Talk That Wants to Get Out (LambdAle 2018)

These are the slides for my talk at LambdAle 2018 in London, UK.

The whole idea here is to show people how Lambda Calculus works, how to encode data using functions and demonstrate its Turing-Completeness. I then proceed to explain combinators and replace the functions with combinators and then replace the combinators themselves with only S and K, the smallest combinator base possible for completeness.

This talk is inspired in the excellent "Programming With Nothing" by Tom Stuart, the main difference is that in this one I use JavaScript and I also added combinators and SK calculus. My take is a bit different, but Tom's talk is definitely worth watching (one of the best I've ever seen).

Lucas Fernandes da Costa

September 01, 2018
Tweet

More Decks by Lucas Fernandes da Costa

Other Decks in Programming

Transcript

  1. 100 1 There is a Bluebird in my Talk that

    Wants to Get out Programming with birds THEWIZARDLUCAS
  2. 100 3 I want to make it awful. And I'm

    not the first one. Programming with nothing By Tom Stuart
  3. 100 4 I want to make it awful. But I

    want to take it one step further. z Programming with nothing By Tom Stuart
  4. 100 8 Ruin JavaScript Ruin JavaScript with birds Ruin JavaScript

    and The Birds Part 1 Part 2 Part 3 Apologise Part 4
  5. 100 10 We are spoiled We program with way too

    much: • Objects • Classes/Inheritance • Booleans • Numbers • Builtin functions • Builtin data structures
  6. 100 12 We are only allowed to use four kinds

    of tokens THE RULES 1 2 3 4 Identifier ID λID. E E E (E) Abstraction Application Grouping
  7. 100 13 We are only allowed to use four kinds

    of tokens THE RULES 1 2 3 4 Identifier ID λID. E E E (E) Abstraction Application Grouping Yes, all functions only take one argument I will use assignments to make this more convenient In JavaScript this is E(E)
  8. 100 17 Why do we need booleans anyway? Replacing Numbers

    if { this } else { that } const val = boolean ? "Yes": "No"
  9. 100 18 Why do we need booleans anyway? Replacing Numbers

    if { this } else { that } const val = boolean ? "Yes": "No" const TRUE = a => b => a Always selects the first value.
  10. 100 19 Why do we need booleans anyway? Replacing Numbers

    if { this } else { that } const val = boolean ? "Yes": "No" const FALSE = a => b => b Always selects the second value.
  11. 100 27 Booleans Replacing Numbers What about the if keyword?

    BOOLEAN { this } { that } The boolean itself is our this.
  12. 100 47 The successor function Replacing arithmetics const ONE =

    f => x => f(x) const TWO = f => x => f(f(x))
  13. 100 48 The successor function Replacing arithmetics const ONE =

    f => x => f(x) const SUCCESSOR = n => f => x => f(n(f)(x)) const TWO = f => x => f(f(x))
  14. 100 49 The successor function Replacing arithmetics const ONE =

    f => x => f(x) SUCCESSOR(ONE) const TWO = f => x => f(f(x)) const SUCCESSOR = n => f => x => f(n(f)(x))
  15. 100 50 The successor function Replacing arithmetics const ONE =

    f => x => f(x) SUCCESSOR(ONE) f => x => f((ONE(f))(x)) const TWO = f => x => f(f(x)) const SUCCESSOR = n => f => x => f(n(f)(x))
  16. 100 51 The successor function Replacing arithmetics const ONE =

    f => x => f(x) SUCCESSOR(ONE) f => x => f((ONE(f))(x)) f => x => f((x => f(x))(x)) const TWO = f => x => f(f(x)) const SUCCESSOR = n => f => x => f(n(f)(x))
  17. 100 52 The successor function Replacing arithmetics const ONE =

    f => x => f(x) f => x => f((ONE(f))(x)) f => x => f((x => f(x))(x)) f => x => f(f(x)) const TWO = f => x => f(f(x)) const SUCCESSOR = n => f => x => f(n(f)(x)) SUCCESSOR(ONE)
  18. 100 53 The addition function Replacing arithmetics const TWO =

    f => x => f(f(x)) const ONE = f => x => f(x)
  19. 100 54 The addition function Replacing arithmetics const TWICE =

    f => x => f(f(x)) const ONE = f => x => f(x)
  20. 100 74 Replacing arithmetics { 1, 2 } { 2,

    3 } Incrementing Pairs { 0, 1 } { 0, 0 }
  21. 100 75 Replacing arithmetics { 1, 2 } { 2,

    3 } { 4, 5 } Incrementing Pairs { 0, 1 } { 0, 0 }
  22. 100 76 Replacing arithmetics { 1, 2 } { 2,

    3 } { 4, 5 } { 5, 6 } Incrementing Pairs { 0, 1 } { 0, 0 }
  23. 100 77 Replacing arithmetics { 1, 2 } { 2,

    3 } { 4, 5 } { 5, 6 } { 0, 0 } Thrice Incrementing Pairs { 0, 1 } { 0, 0 }
  24. 100 78 Replacing arithmetics { 1, 2 } { 2,

    3 } { 4, 5 } { 5, 6 } { 0, 0 } Thrice { 0, 1 } Incrementing Pairs { 0, 1 } { 0, 0 } x1
  25. 100 79 Replacing arithmetics { 1, 2 } { 2,

    3 } { 4, 5 } { 5, 6 } { 0, 0 } Thrice { 1, 2 } Incrementing Pairs { 0, 1 } { 0, 0 } x2
  26. 100 80 Replacing arithmetics { 1, 2 } { 2,

    3 } { 4, 5 } { 5, 6 } { 0, 0 } Thrice { 2, 3 } Incrementing Pairs { 0, 1 } { 0, 0 } x3
  27. 100 81 Replacing arithmetics { 1, 2 } { 2,

    3 } { 4, 5 } { 5, 6 } { 0, 0 } Thrice { 2, 3 } Incrementing Pairs { 0, 1 } { 0, 0 } x3
  28. 100 82 Replacing arithmetics { 1, 2 } { 2,

    3 } { 4, 5 } { 5, 6 } { 0, 0 } Three { 2, 3 } Incrementing Pairs { 0, 1 } { 0, 0 } x3 Predecessor
  29. 100 88 AND { true } { true } is

    true AND Replacing Boolean Operators Any other combinations are false
  30. 100 89 AND { true } { true } is

    true AND Replacing Boolean Operators Any other combinations are false
  31. 100 90 AND Replacing Boolean Operators If a is true

    b must be true If a is false it returns itself
  32. 100 91 It is true if any values are {

    true } OR Replacing Boolean Operators
  33. 100 92 It is true if any values are {

    true } OR Replacing Boolean Operators
  34. 100 93 It is true if any values are {

    true } OR Replacing Boolean Operators If a is true it returns itself, otherwise tries b
  35. 100 97 NOT Replacing Boolean Operators Inverts any { true

    } and { false } Takes a boolean f and applies it to the arguments in reverse order
  36. 100 98 NOT Replacing Boolean Operators Inverts the selector Takes

    a boolean f and applies it to the arguments in reverse order
  37. 100 99 NOT Replacing Boolean Operators Inverts the selector Takes

    a boolean f and applies it to the arguments in reverse order
  38. 100 100 IS ZERO Replacing Boolean Operators Checks if a

    is zero If n is zero, it will return the last TRUE
  39. 100 111 Ruining Javascript We could replace the names of

    these functions by their definitions and remove all variable names Replacing everything with functions
  40. 100 114 Combinators Our Birds Functions that don't have free

    variables. const combinator = a => b => a const withContext = a => b(a) a is bound and b is free both a and b are bound
  41. 100 115 To Mock a Mockingbird C o m b

    i n a t o r s a n d B i r d s
  42. 100 125 Combinators const SUCCESSOR = n => f =>

    B(f)(n(f)) Replacing Functions (Successor)
  43. 100 126 Combinators const SUCCESSOR = n => f =>

    B(f)(n(f)) Replacing Functions (Successor)
  44. 100 127 Combinators const SUCCESSOR = n => f =>

    B(f)(n(f)) const SUCCESSOR = S(B) Replacing Functions (Successor)
  45. 100 134 Ruining Javascript Haskell's Data.Aviary.Birds This module is intended

    for illustration (the type signatures!) rather than utility.
  46. 100 137 WHAT IF I TOLD YOU YOU ONLY NEED

    TWO COMBINATORS? Yes, that's right. Two.
  47. 100 140 SK Calculus Replacing Numbers People also call it

    SKI Calculus Because it's more convenient to have I
  48. 100 141 SK Calculus Replacing Numbers People also call it

    SKI Calculus const I = S(K)(K) Because it's more convenient to have I
  49. 100 145 SK Calculus Replacing Numbers const KI = K(I)

    const B = S(K(S))(K) const V = PAIRING
  50. 100 150 What does this mean? If we can replace

    all code by functions Replace all functions by combinators
  51. 100 151 What does this mean? If we can replace

    all code by functions Replace all functions by combinators And replace all combinators by S and K
  52. 100 152 What does this mean? If we can replace

    all code by functions Replace all functions by combinators And replace all combinators by S and K Then we can replace all code by S and K
  53. 100 155 Apologising Part 4 Functional Programming Combinatory Logic Computability

    Theory History of Math Compiler Theory Language Design Recursion Wanting to frame
 Gödel pictures to hang in your room
  54. 100 156 Thank you! Shhh, no tears. Only lambdas now.

    @THEWIZARDLUCAS (TWITTER) @LUCASFCOSTA (GITHUB) LUCASFCOSTA.COM
  55. 100 157 References http://codon.com/programming-with-nothing http://www.angelfire.com/tx4/cus/combinator/birds.html https://bit.ly/2xpcPKn A Flock of Functions

    - Gabriel Lebec List of Notorious Combinators The blog post for the talk I mentioned in the beginning https://speakerdeck.com/tomstuart/programming-with-nothing Slides for the talk "Programming with Nothing" https://amzn.to/2BVVsa1 To Mock a Mockingbird - Raymond Smullyan http://computationbook.com Understanding Computation - Tom Stuart https://www.youtube.com/watch?v=_kYGDJSm0gE - ASU Lectures - Lambda Calculus by Adam Doupé
  56. 100 158 Thank you! Shhh, no tears. Only lambdas now.

    @THEWIZARDLUCAS (TWITTER) @LUCASFCOSTA (GITHUB) LUCASFCOSTA.COM