Lucas Fernandes da Costa
September 01, 2018
110

# 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

## Transcript

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

Wants to Get out Programming with birds THEWIZARDLUCAS

3. ### 100 3 I want to make it awful. And I'm

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

want to take it one step further. z Programming with nothing By Tom Stuart

Part 2
7. ### 100 7 Ruin JavaScript Ruin JavaScript with birds Ruin JavaScript

and The Birds Part 1 Part 2 Part 3
8. ### 100 8 Ruin JavaScript Ruin JavaScript with birds Ruin JavaScript

and The Birds Part 1 Part 2 Part 3 Apologise Part 4

10. ### 100 10 We are spoiled We program with way too

much: • Objects • Classes/Inheritance • Booleans • Numbers • Builtin functions • Builtin data structures
11. ### 100 11 This is what we're going to rewrite T

H E W R E C K
12. ### 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
13. ### 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)

E C K

17. ### 100 17 Why do we need booleans anyway? Replacing Numbers

if { this } else { that } const val = boolean ? "Yes": "No"
18. ### 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.
19. ### 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.
20. ### 100 20 Booleans Replacing Numbers const FALSE = a =>

b => b const TRUE = a => b => a
21. ### 100 21 Booleans Replacing Numbers const SECOND = a =>

b => b const FIRST = a => b => a

24. ### 100 24 Booleans Replacing Numbers What about the if keyword?

if { this } else { that }
25. ### 100 25 Booleans Replacing Numbers What about the if keyword?

BOOLEAN { this } else { that }
26. ### 100 26 Booleans Replacing Numbers What about the if keyword?

BOOLEAN { this } { that }
27. ### 100 27 Booleans Replacing Numbers What about the if keyword?

BOOLEAN { this } { that } The boolean itself is our this.

34. ### 100 34 What is a number, anyway? Replacing Numbers 2

Representation Meaning Meaning

Numbers
36. ### 100 36 How can we represent quantities with functions? Replacing

Numbers Function applications!
37. ### 100 37 How can we represent quantities with functions? Replacing

Numbers Function applications!
38. ### 100 38 How can we represent quantities with functions? Replacing

Numbers Function applications!
39. ### 100 39 How can we represent quantities with functions? Replacing

Numbers Function applications!

47. ### 100 47 The successor function Replacing arithmetics const ONE =

f => x => f(x) const TWO = f => x => f(f(x))
48. ### 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))
49. ### 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))
50. ### 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))
51. ### 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))
52. ### 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)
53. ### 100 53 The addition function Replacing arithmetics const TWO =

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

f => x => f(f(x)) const ONE = f => x => f(x)

we want.

{ 0, 0 }
73. ### 100 73 Replacing arithmetics { 1, 2 } Incrementing Pairs

{ 0, 1 } { 0, 0 }
74. ### 100 74 Replacing arithmetics { 1, 2 } { 2,

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

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

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

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

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

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

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

3 } { 4, 5 } { 5, 6 } { 0, 0 } Thrice { 2, 3 } Incrementing Pairs { 0, 1 } { 0, 0 } x3
82. ### 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

0) First of

K times

88. ### 100 88 AND { true } { true } is

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

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

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

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

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

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

} and { false }
95. ### 100 95 NOT Replacing Boolean Operators Inverts any { true

} and { false }
96. ### 100 96 NOT Replacing Boolean Operators Inverts any { true

} and { false }
97. ### 100 97 NOT Replacing Boolean Operators Inverts any { true

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

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

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

is zero If n is zero, it will return the last TRUE
101. ### 100 101 EQUALS Replacing Boolean Operators Checks if a equals

b Checks if both n <= k and k <= n
102. ### 100 102 GREATER THAN Replacing Boolean Operators The opposite of

lesser or equal

111. ### 100 111 Ruining Javascript We could replace the names of

these functions by their definitions and remove all variable names Replacing everything with functions
112. ### 100 112 Unleash Hell Ruining Javascript But I will save

you from this pain for now

114. ### 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
115. ### 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

124. ### 100 124 Combinators Replacing Functions (Successor) const SUCCESSOR = n

=> f => x => f(n(f)(x))
125. ### 100 125 Combinators const SUCCESSOR = n => f =>

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

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

B(f)(n(f)) const SUCCESSOR = S(B) Replacing Functions (Successor)
128. ### 100 128 Combinators Replacing Functions (Addition) const ADDITION = n

=> k => n(SUCESSOR)(k)
129. ### 100 129 Combinators Replacing Functions (Addition) const ADDITION = n

=> k => n(S(B))(k)
130. ### 100 130 Combinators Replacing Functions (Addition) const ADDITION = k

=> Th(S(B))(k)

133. ### 100 133 Ruining Javascript B Th C K KI V

S Nice birds m8
134. ### 100 134 Ruining Javascript Haskell's Data.Aviary.Birds This module is intended

for illustration (the type signatures!) rather than utility.

137. ### 100 137 WHAT IF I TOLD YOU YOU ONLY NEED

TWO COMBINATORS? Yes, that's right. Two.

SKI Calculus
140. ### 100 140 SK Calculus Replacing Numbers People also call it

SKI Calculus Because it's more convenient to have I
141. ### 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

144. ### 100 144 SK Calculus Replacing Numbers const KI = K(I)

const B = S(K(S))(K)
145. ### 100 145 SK Calculus Replacing Numbers const KI = K(I)

const B = S(K(S))(K) const V = PAIRING
146. ### 100 146 SK Calculus Replacing Numbers const V = ((S(K((S((S(K((S(KS)

)K)))S))(KK)))) ((S(K(S((SK)K))))K))
147. ### 100 147 SK Calculus Replacing Numbers const V = ((S(K((S((S(K((S(KS)

)K)))S))(KK)))) ((S(K(S((SK)K))))K)) Easy.

149. ### 100 149 What does this mean? If we can replace

all code by functions
150. ### 100 150 What does this mean? If we can replace

all code by functions Replace all functions by combinators
151. ### 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
152. ### 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

155. ### 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