SlideShare a Scribd company logo
1 of 170
Download to read offline
Lambda?You Keep Using that Letter
@KevlinHenney
AWS
Half-Life
wavelength
decay constant
calculus
-calculus
In 1911 Russell & Whitehead published Principia
Mathematica, with the goal of providing a solid
foundation for all of mathematics.
In 1911 Russell & Whitehead published Principia
Mathematica, with the goal of providing a solid
foundation for all of mathematics. In 1931 Gödel’s
Incompleteness Theorem shattered the dream,
showing that for any consistent axiomatic system
there will always be theorems that cannot be
proven within the system.
Adrian Colyer
https://blog.acolyer.org/2020/02/03/measure-mismeasure-fairness/
One premise of many models of fairness in
machine learning is that you can measure (‘prove’)
fairness of a machine learning model from within
the system – i.e. from properties of the model itself
and perhaps the data it is trained on.
To show that a machine learning model is fair, you
need information from outside of the system.
Adrian Colyer
https://blog.acolyer.org/2020/02/03/measure-mismeasure-fairness/
We demand rigidly
defined areas of doubt
and uncertainty!
Despite the fancy name, a
lambda is just a function...
peculiarly... without a name.
https://rubymonk.com/learning/books/1-ruby-primer/chapters/34-lambdas-and-blocks-in-ruby/lessons/77-lambdas-in-ruby
There are only two hard things
in Computer Science: cache
invalidation and naming things.
Phil Karlton
There are only two hard things
in Computer Science: cache
invalidation and naming things.
Phil Karlton
We select a particular list of
symbols, consisting of the
symbols { , }, ( , ), λ, [ , ],
and an enumerably infinite
set of symbols a, b, c, · · · to
be called variables.
And we define the word
formula to mean any finite
sequence of symbols out of
this list.
f(x) = formula
f → λ x· formula
f → λ x· y x
variable
abstraction
application
f → λ x· y x
abbreviation free variable
bound variable
square(x) = x × x
square → λ x· x × x
square → λ 😠· 😠 × 😠
☐ → λ 😠· 😠 × 😠
☐ 7
square 7
(λ x· x × x) 7
AN UNSOLVEABLE
PROBLEM OF
ELEMENTARY
NUMBER THEORY
NUMBER
0
0 → λ f· λ x· x
1 → λ f· λ x· f(x)
2 → λ f· λ x· f(f(x))
3 → λ f· λ x· f(f(f(x)))
4 → λ f· λ x· f(f(f(f(x))))
5 → λ f· λ x· f(f(f(f(f(x)))))
0 → λ f x· x
1 → λ f x· f(x)
2 → λ f x· f(f(x))
3 → λ f x· f(f(f(x)))
4 → λ f x· f(f(f(f(x))))
5 → λ f x· f(f(f(f(f(x)))))
0 → λ f x· x
1 → λ f x· f x
2 → λ f x· f2 x
3 → λ f x· f3 x
4 → λ f x· f4 x
5 → λ f x· f5 x
6
0 → λ f x· f0 x
1 → λ f x· f1 x
2 → λ f x· f2 x
3 → λ f x· f3 x
4 → λ f x· f4 x
5 → λ f x· f5 x
6
7
7.times
7.times {|i| puts i}
7.times {println it}
0
1
2
3
4
5
You may have heard of lambdas
before. Perhaps you’ve used
them in other languages.
https://rubymonk.com/learning/books/1-ruby-primer/chapters/34-lambdas-and-blocks-in-ruby/lessons/77-lambdas-in-ruby
function square(x) {
return x * x
}
square = function(x) {
return x * x
}
square = (x) => {
return x * x
}
square = x => {
return x * x
}
square = x => x * x
square(7)
(x => x * x)(7)
They’re anonymous, little
functional spies sneaking
into the rest of your code.
https://rubymonk.com/learning/books/1-ruby-primer/chapters/34-lambdas-and-blocks-in-ruby/lessons/77-lambdas-in-ruby
Excel is the world’s
most popular
functional language
Simon Peyton-Jones
(lambda (x) (* x x))
((lambda (x) (* x x)) 7)
http://xkcd.com/224/
http://xkcd.com/224/
http://xkcd.com/224/
http://xkcd.com/224/
We lost the documentation on quantum mechanics.
You'll have to decode the regexes yourself.
(real x) real: x * x
proc (real) real square;
square := (real x) real: x * x;
real result := square (7);
((real x) real: x * x) (7)
Lambdas in Ruby are
also objects, just like
everything else!
https://rubymonk.com/learning/books/1-ruby-primer/chapters/34-lambdas-and-blocks-in-ruby/lessons/77-lambdas-in-ruby
The venerable master Qc Na was walking with his
student, Anton. Hoping to prompt the master into
a discussion, Anton said “Master, I have heard
that objects are a very good thing — is this true?”
Qc Na looked pityingly at his student and replied,
“Foolish pupil — objects are merely a poor man’s
closures.”
http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
The concept of closures was developed in the
1960s for the mechanical evaluation of
expressions in the λ-calculus.
Peter J. Landin defined the term closure in
1964 as having an environment part and a
control part.
https://en.wikipedia.org/wiki/Closure_(computer_programming)
Joel Moses credits Landin with introducing
the term closure to refer to a lambda
expression whose open bindings (free
variables) have been closed by (or bound in)
the lexical environment, resulting in a closed
expression, or closure.
https://en.wikipedia.org/wiki/Closure_(computer_programming)
This usage was subsequently adopted by
Sussman and Steele when they defined
Scheme in 1975, a lexically scoped variant of
LISP, and became widespread.
https://en.wikipedia.org/wiki/Closure_(computer_programming)
Chastised, Anton took his leave from his master
and returned to his cell, intent on studying
closures. He carefully read the entire “Lambda:
The Ultimate...” series of papers and its cousins,
and implemented a small Scheme interpreter with a
closure-based object system.
http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
(define (eval exp env)
(cond ((self-evaluating? exp) exp)
((variable? exp) (lookup-variable-value exp env))
((quoted? exp) (text-of-quotation exp))
((assignment? exp) (eval-assignment exp env))
((definition? exp) (eval-definition exp env))
((if? exp) (eval-if exp env))
((lambda? exp)
(make-procedure (lambda-parameters exp)
(lambda-body exp)
env))
((begin? exp)
(eval-sequence (begin-actions exp) env))
((cond? exp) (eval (cond->if exp) env))
((application? exp)
(apply (eval (operator exp) env)
(list-of-values (operands exp) env)))
(else
(error "Unknown expression type -- EVAL" exp))))
This work developed out of an initial attempt
to understand the actorness of actors.
This interpreter attempted to intermix the
use of actors and LISP lambda expressions in
a clean manner.
“Scheme: An Interpreter for Extended Lambda Calculus”
Gerald Jay Sussman & Guy L Steele Jr
When it was completed, we discovered that
the “actors” and the lambda expressions
were identical in implementation.
“Scheme: An Interpreter for Extended Lambda Calculus”
Gerald Jay Sussman & Guy L Steele Jr
On his next walk with Qc Na, Anton attempted
to impress his master by saying “Master, I have
diligently studied the matter, and now understand
that objects are truly a poor man’s closures.”
Qc Na responded by hitting Anton with his stick,
saying “When will you learn? Closures are a poor
man’s object.”
http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
At that moment, Anton became enlightened.
http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
λ-calculus was the
first object-oriented
language.
const newStack = () => {
const items = []
return {
depth: () => items.length,
top: () => items[0],
push: newTop => { items.unshift(newTop) },
pop: () => { items.shift() },
}
}
const newStack = () => {
const items = []
return {
depth: () => items.length,
top: () => items[0],
push: newTop => { items.unshift(newTop) },
pop: () => { items.shift() },
}
}
const newStack = () => {
const items = []
return {
depth: () => items.length,
top: () => items[0],
push: newTop => { items.unshift(newTop) },
pop: () => { items.shift() },
}
}
const newStack = () => {
const items = []
return {
depth: () => items.length,
top: () => items[0],
push: newTop => { items.unshift(newTop) },
pop: () => { items.shift() },
}
}
One of the most powerful
mechanisms for program
structuring [...] is the block
and procedure concept.
Ole-Johan Dahl and C A R Hoare
“Hierarchical Program Structures”
begin
ref(Rock) array items(1:capacity);
integer count;
integer procedure Depth; ...
ref(Rock) procedure Top; ...
procedure Push(top); ...
procedure Pop; ...
count := 0
end;
A procedure which is capable of
giving rise to block instances which
survive its call will be known as a
class; and the instances will be
known as objects of that class.
Ole-Johan Dahl and C A R Hoare
“Hierarchical Program Structures”
class Stack(capacity);
integer capacity;
begin
ref(Rock) array items(1:capacity);
integer count;
integer procedure Depth; ...
ref(Rock) procedure Top; ...
procedure Push(top); ...
procedure Pop; ...
count := 0
end;
We could, of course, use any notation
we want; do not laugh at notations;
invent them, they are powerful.
In fact, mathematics is, to a large
extent, invention of better notations.
Richard Feynman
lambda
function
fn
[]
[](){}
[](){}()
=>
->
()->{}
x -> x * x
:t x -> x * x
x -> x * x :: Num a => a -> a
lambda x: x * x
type(lambda x: x * x)
class<'function'>
x -> x * x
var square = x -> x * x;
var square = x -> x * x;
()->{}
apply
test
accept
get
()->{}((Runnable)()->{}).run()
f → λ x· y x
variable
abstraction
application
f → λ x· ☹️
variable
abstraction
“Oh God,” muttered Ford, slumped against
a bulkhead and started to count to ten.
He was desperately worried that one day
sentient life forms would forget how to do this.
Only by counting could humans demonstrate
their independence of computers.
0 → λ f· λ x· x
1 → λ f· λ x· f(x)
2 → λ f· λ x· f(f(x))
3 → λ f· λ x· f(f(f(x)))
4 → λ f· λ x· f(f(f(f(x))))
5 → λ f· λ x· f(f(f(f(f(x)))))
_0 = f => x => x
_1 = f => x => f(x)
_2 = f => x => f(f(x))
_3 = f => x => f(f(f(x)))
_4 = f => x => f(f(f(f(x))))
_5 = f => x => f(f(f(f(f(x)))
_0
_0(n => n + 1)
_0(n => n + 1)(0)
_1(n => n + 1)(0)
_2(n => n + 1)(0)
_3(n => n + 1)(0)
_4(n => n + 1)(0)
_5(n => n + 1)(0)
0
1
2
3
4
5
_0(n => n + ‘1’)(‘’)
_1(n => n + ‘1’)(‘’)
_2(n => n + ‘1’)(‘’)
_3(n => n + ‘1’)(‘’)
_4(n => n + ‘1’)(‘’)
_5(n => n + ‘1’)(‘’)
1
11
111
1111
11111
square
square = m => _2(m)
square(_7)
square(_7)(n => n + 1)
square(_7)(n => n + 1)(0)
49
true
false
true → λ a b· a
false → λ a b· b
7 * 7 < limit
ifTrue: [^ ‘👍’]
ifFalse: [^ ‘👎’]
True
ifTrue: toDo ifFalse: ignore
^ toDo value
False
ifTrue: ignore ifFalse: toDo
^ toDo value
false → λ a b· b
false → λ 🙂☹· ☹️
false → λ f x· x
false = 0
pair → λ x y f· f(x)(y)
first → λ p· p(λ x y· x)
second → λ p· p(λ x y· y)
pair → λ x y f· f x y
first → λ p· p true
second → λ p· p false
nil → λ x· true
cons → λ x y f· f x y
car → λ p· p true
cdr → λ p· p false
nil → λ x· true
https://twitter.com/richardadalton/status/591534529086693376
def fizzbuzz(n)
{
result = ''
if (n % 3 == 0)
result += 'Fizz'
if (n % 5 == 0)
result += 'Buzz'
if (!result)
result += n
result
}
The default action is executed only if some
previous actions were not executed.
Maciej Piróg
“FizzBuzz in Haskell by Embedding a Domain-Specific Language”
def fizzbuzz(n)
{
[0: 'Fizz'].get(n % 3, '') +
[0: 'Buzz'].get(n % 5, '') ?:
n.toString()
}
The default action is executed only if some
previous actions were not executed.
We ask if we can accomplish this without
having to check the conditions for the previous
actions twice.
Maciej Piróg
“FizzBuzz in Haskell by Embedding a Domain-Specific Language”
def fizzbuzz(n)
{
if (n % 15 == 0)
'FizzBuzz'
else if (n % 3 == 0)
'Fizz'
else if (n % 5 == 0)
'Buzz'
else
n.toString()
}
def fizzbuzz(n)
{
if (n % 3 == 0 && n % 5 == 0)
'FizzBuzz'
else if (n % 3 == 0)
'Fizz'
else if (n % 5 == 0)
'Buzz'
else
n.toString()
}
The default action is executed only if some
previous actions were not executed.
We ask if we can accomplish this without
having to check the conditions for the previous
actions twice; in other words, if we can make
the control flow follow the information flow
without loosing modularity.
Maciej Piróg
“FizzBuzz in Haskell by Embedding a Domain-Specific Language”
def fizzbuzz(n)
{
id = {x -> x}
}
def fizzbuzz(n)
{
id = {it}
val = {x -> {_ -> x}}
}
def fizzbuzz(n)
{
id = {it}
val = {{_ -> it}}
fizz = n % 3 ? id : {val('Fizz' + it(''))}
buzz = n % 5 ? id : {val('Buzz' + it(''))}
fizz(buzz({it.toString()}))(n)
}
(1..100).each {println fizzbuzz(it)}
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
I have yet to see any problem,
however complicated, which,
when you looked at it in the
right way, did not become still
more complicated.
Anderson's Law
We shall not cease from exploration
And the end of all our exploring
Will be to arrive where we started
And know the place for the first time.
T S Eliot
Lambda? You Keep Using that Letter
Lambda? You Keep Using that Letter

More Related Content

What's hot

Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeKevlin Henney
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Leonardo Borges
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data scienceJohn Cant
 
Java Generics for Dummies
Java Generics for DummiesJava Generics for Dummies
Java Generics for Dummiesknutmork
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedSusan Potter
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskellJongsoo Lee
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...Philip Schwarz
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Bryan O'Sullivan
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Bryan O'Sullivan
 
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions Ganesh Samarthyam
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Bryan O'Sullivan
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsJohn De Goes
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Paulo Morgado
 

What's hot (20)

Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015Futures e abstração - QCon São Paulo 2015
Futures e abstração - QCon São Paulo 2015
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data science
 
Java Generics for Dummies
Java Generics for DummiesJava Generics for Dummies
Java Generics for Dummies
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Comparing JVM languages
Comparing JVM languagesComparing JVM languages
Comparing JVM languages
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4
 
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
OCP Java SE 8 Exam - Sample Questions - Lambda Expressions
 
Real World Haskell: Lecture 6
Real World Haskell: Lecture 6Real World Haskell: Lecture 6
Real World Haskell: Lecture 6
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
 
Kotlin, why?
Kotlin, why?Kotlin, why?
Kotlin, why?
 

Similar to Lambda? You Keep Using that Letter

Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevJavaDayUA
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Philip Schwarz
 
Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Hakka Labs
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaPhilip Schwarz
 
Principles of functional progrmming in scala
Principles of functional progrmming in scalaPrinciples of functional progrmming in scala
Principles of functional progrmming in scalaehsoon
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsEelco Visser
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2Hang Zhao
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойSigma Software
 
Introduction to idris
Introduction to idrisIntroduction to idris
Introduction to idrisConor Farrell
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
Kotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsKotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsFranco Lombardo
 

Similar to Lambda? You Keep Using that Letter (20)

Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Monads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy DyagilevMonads and Monoids by Oleksiy Dyagilev
Monads and Monoids by Oleksiy Dyagilev
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - with ...
 
Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Principles of functional progrmming in scala
Principles of functional progrmming in scalaPrinciples of functional progrmming in scala
Principles of functional progrmming in scala
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
ScalaBlitz
ScalaBlitzScalaBlitz
ScalaBlitz
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
 
Introduction to idris
Introduction to idrisIntroduction to idris
Introduction to idris
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Scala Introduction
Scala IntroductionScala Introduction
Scala Introduction
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Kotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsKotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functions
 

More from Kevlin Henney

The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical ExcellenceKevlin Henney
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical DevelopmentKevlin Henney
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid DeconstructionKevlin Henney
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test CasesKevlin Henney
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-InKevlin Henney
 
Giving Code a Good Name
Giving Code a Good NameGiving Code a Good Name
Giving Code a Good NameKevlin Henney
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Kevlin Henney
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantKevlin Henney
 
The Error of Our Ways
The Error of Our WaysThe Error of Our Ways
The Error of Our WaysKevlin Henney
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersKevlin Henney
 
SOLID Deconstruction
SOLID DeconstructionSOLID Deconstruction
SOLID DeconstructionKevlin Henney
 
Object? You Keep Using that Word
Object? You Keep Using that WordObject? You Keep Using that Word
Object? You Keep Using that WordKevlin Henney
 

More from Kevlin Henney (20)

Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
 
The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical Excellence
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical Development
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid Deconstruction
 
Get Kata
Get KataGet Kata
Get Kata
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test Cases
 
Agility ≠ Speed
Agility ≠ SpeedAgility ≠ Speed
Agility ≠ Speed
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-In
 
Giving Code a Good Name
Giving Code a Good NameGiving Code a Good Name
Giving Code a Good Name
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation Quadrant
 
Code as Risk
Code as RiskCode as Risk
Code as Risk
 
Software Is Details
Software Is DetailsSoftware Is Details
Software Is Details
 
Game of Sprints
Game of SprintsGame of Sprints
Game of Sprints
 
Good Code
Good CodeGood Code
Good Code
 
The Error of Our Ways
The Error of Our WaysThe Error of Our Ways
The Error of Our Ways
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
 
SOLID Deconstruction
SOLID DeconstructionSOLID Deconstruction
SOLID Deconstruction
 
Object? You Keep Using that Word
Object? You Keep Using that WordObject? You Keep Using that Word
Object? You Keep Using that Word
 

Recently uploaded

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 

Recently uploaded (20)

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 

Lambda? You Keep Using that Letter

  • 1. Lambda?You Keep Using that Letter @KevlinHenney
  • 2.
  • 5.
  • 6. In 1911 Russell & Whitehead published Principia Mathematica, with the goal of providing a solid foundation for all of mathematics. In 1911 Russell & Whitehead published Principia Mathematica, with the goal of providing a solid foundation for all of mathematics. In 1931 Gödel’s Incompleteness Theorem shattered the dream, showing that for any consistent axiomatic system there will always be theorems that cannot be proven within the system. Adrian Colyer https://blog.acolyer.org/2020/02/03/measure-mismeasure-fairness/
  • 7. One premise of many models of fairness in machine learning is that you can measure (‘prove’) fairness of a machine learning model from within the system – i.e. from properties of the model itself and perhaps the data it is trained on. To show that a machine learning model is fair, you need information from outside of the system. Adrian Colyer https://blog.acolyer.org/2020/02/03/measure-mismeasure-fairness/
  • 8.
  • 9. We demand rigidly defined areas of doubt and uncertainty!
  • 10.
  • 11. Despite the fancy name, a lambda is just a function... peculiarly... without a name. https://rubymonk.com/learning/books/1-ruby-primer/chapters/34-lambdas-and-blocks-in-ruby/lessons/77-lambdas-in-ruby
  • 12. There are only two hard things in Computer Science: cache invalidation and naming things. Phil Karlton
  • 13. There are only two hard things in Computer Science: cache invalidation and naming things. Phil Karlton
  • 14.
  • 15. We select a particular list of symbols, consisting of the symbols { , }, ( , ), λ, [ , ], and an enumerably infinite set of symbols a, b, c, · · · to be called variables.
  • 16. And we define the word formula to mean any finite sequence of symbols out of this list.
  • 18. f → λ x· formula
  • 19. f → λ x· y x variable abstraction application
  • 20. f → λ x· y x abbreviation free variable bound variable
  • 22. square → λ x· x × x
  • 23. square → λ 😠· 😠 × 😠
  • 24. ☐ → λ 😠· 😠 × 😠
  • 25. ☐ 7
  • 27. (λ x· x × x) 7
  • 28.
  • 31.
  • 32. 0
  • 33. 0 → λ f· λ x· x 1 → λ f· λ x· f(x) 2 → λ f· λ x· f(f(x)) 3 → λ f· λ x· f(f(f(x))) 4 → λ f· λ x· f(f(f(f(x)))) 5 → λ f· λ x· f(f(f(f(f(x)))))
  • 34. 0 → λ f x· x 1 → λ f x· f(x) 2 → λ f x· f(f(x)) 3 → λ f x· f(f(f(x))) 4 → λ f x· f(f(f(f(x)))) 5 → λ f x· f(f(f(f(f(x)))))
  • 35. 0 → λ f x· x 1 → λ f x· f x 2 → λ f x· f2 x 3 → λ f x· f3 x 4 → λ f x· f4 x 5 → λ f x· f5 x 6
  • 36. 0 → λ f x· f0 x 1 → λ f x· f1 x 2 → λ f x· f2 x 3 → λ f x· f3 x 4 → λ f x· f4 x 5 → λ f x· f5 x 6
  • 37. 7
  • 42. You may have heard of lambdas before. Perhaps you’ve used them in other languages. https://rubymonk.com/learning/books/1-ruby-primer/chapters/34-lambdas-and-blocks-in-ruby/lessons/77-lambdas-in-ruby
  • 44. square = function(x) { return x * x }
  • 45. square = (x) => { return x * x }
  • 46. square = x => { return x * x }
  • 47. square = x => x * x
  • 49. (x => x * x)(7)
  • 50. They’re anonymous, little functional spies sneaking into the rest of your code. https://rubymonk.com/learning/books/1-ruby-primer/chapters/34-lambdas-and-blocks-in-ruby/lessons/77-lambdas-in-ruby
  • 51. Excel is the world’s most popular functional language Simon Peyton-Jones
  • 52.
  • 53. (lambda (x) (* x x))
  • 54. ((lambda (x) (* x x)) 7)
  • 58. http://xkcd.com/224/ We lost the documentation on quantum mechanics. You'll have to decode the regexes yourself.
  • 59.
  • 60. (real x) real: x * x
  • 61. proc (real) real square; square := (real x) real: x * x; real result := square (7);
  • 62. ((real x) real: x * x) (7)
  • 63. Lambdas in Ruby are also objects, just like everything else! https://rubymonk.com/learning/books/1-ruby-primer/chapters/34-lambdas-and-blocks-in-ruby/lessons/77-lambdas-in-ruby
  • 64. The venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said “Master, I have heard that objects are a very good thing — is this true?” Qc Na looked pityingly at his student and replied, “Foolish pupil — objects are merely a poor man’s closures.” http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
  • 65. The concept of closures was developed in the 1960s for the mechanical evaluation of expressions in the λ-calculus. Peter J. Landin defined the term closure in 1964 as having an environment part and a control part. https://en.wikipedia.org/wiki/Closure_(computer_programming)
  • 66. Joel Moses credits Landin with introducing the term closure to refer to a lambda expression whose open bindings (free variables) have been closed by (or bound in) the lexical environment, resulting in a closed expression, or closure. https://en.wikipedia.org/wiki/Closure_(computer_programming)
  • 67. This usage was subsequently adopted by Sussman and Steele when they defined Scheme in 1975, a lexically scoped variant of LISP, and became widespread. https://en.wikipedia.org/wiki/Closure_(computer_programming)
  • 68. Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire “Lambda: The Ultimate...” series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
  • 69.
  • 70. (define (eval exp env) (cond ((self-evaluating? exp) exp) ((variable? exp) (lookup-variable-value exp env)) ((quoted? exp) (text-of-quotation exp)) ((assignment? exp) (eval-assignment exp env)) ((definition? exp) (eval-definition exp env)) ((if? exp) (eval-if exp env)) ((lambda? exp) (make-procedure (lambda-parameters exp) (lambda-body exp) env)) ((begin? exp) (eval-sequence (begin-actions exp) env)) ((cond? exp) (eval (cond->if exp) env)) ((application? exp) (apply (eval (operator exp) env) (list-of-values (operands exp) env))) (else (error "Unknown expression type -- EVAL" exp))))
  • 71. This work developed out of an initial attempt to understand the actorness of actors. This interpreter attempted to intermix the use of actors and LISP lambda expressions in a clean manner. “Scheme: An Interpreter for Extended Lambda Calculus” Gerald Jay Sussman & Guy L Steele Jr
  • 72. When it was completed, we discovered that the “actors” and the lambda expressions were identical in implementation. “Scheme: An Interpreter for Extended Lambda Calculus” Gerald Jay Sussman & Guy L Steele Jr
  • 73. On his next walk with Qc Na, Anton attempted to impress his master by saying “Master, I have diligently studied the matter, and now understand that objects are truly a poor man’s closures.” Qc Na responded by hitting Anton with his stick, saying “When will you learn? Closures are a poor man’s object.” http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
  • 74. At that moment, Anton became enlightened. http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
  • 75.
  • 76. λ-calculus was the first object-oriented language.
  • 77.
  • 78. const newStack = () => { const items = [] return { depth: () => items.length, top: () => items[0], push: newTop => { items.unshift(newTop) }, pop: () => { items.shift() }, } }
  • 79. const newStack = () => { const items = [] return { depth: () => items.length, top: () => items[0], push: newTop => { items.unshift(newTop) }, pop: () => { items.shift() }, } }
  • 80. const newStack = () => { const items = [] return { depth: () => items.length, top: () => items[0], push: newTop => { items.unshift(newTop) }, pop: () => { items.shift() }, } }
  • 81. const newStack = () => { const items = [] return { depth: () => items.length, top: () => items[0], push: newTop => { items.unshift(newTop) }, pop: () => { items.shift() }, } }
  • 82.
  • 83. One of the most powerful mechanisms for program structuring [...] is the block and procedure concept. Ole-Johan Dahl and C A R Hoare “Hierarchical Program Structures”
  • 84. begin ref(Rock) array items(1:capacity); integer count; integer procedure Depth; ... ref(Rock) procedure Top; ... procedure Push(top); ... procedure Pop; ... count := 0 end;
  • 85. A procedure which is capable of giving rise to block instances which survive its call will be known as a class; and the instances will be known as objects of that class. Ole-Johan Dahl and C A R Hoare “Hierarchical Program Structures”
  • 86. class Stack(capacity); integer capacity; begin ref(Rock) array items(1:capacity); integer count; integer procedure Depth; ... ref(Rock) procedure Top; ... procedure Push(top); ... procedure Pop; ... count := 0 end;
  • 87. We could, of course, use any notation we want; do not laugh at notations; invent them, they are powerful. In fact, mathematics is, to a large extent, invention of better notations. Richard Feynman
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 96. fn
  • 97.
  • 98. []
  • 101.
  • 102. =>
  • 103. ->
  • 104. ()->{}
  • 105.
  • 106. x -> x * x
  • 107. :t x -> x * x
  • 108. x -> x * x :: Num a => a -> a
  • 109. lambda x: x * x
  • 112. x -> x * x
  • 113. var square = x -> x * x;
  • 114. var square = x -> x * x;
  • 115. ()->{}
  • 116.
  • 119. f → λ x· y x variable abstraction application
  • 120. f → λ x· ☹️ variable abstraction
  • 121.
  • 122. “Oh God,” muttered Ford, slumped against a bulkhead and started to count to ten. He was desperately worried that one day sentient life forms would forget how to do this. Only by counting could humans demonstrate their independence of computers.
  • 123. 0 → λ f· λ x· x 1 → λ f· λ x· f(x) 2 → λ f· λ x· f(f(x)) 3 → λ f· λ x· f(f(f(x))) 4 → λ f· λ x· f(f(f(f(x)))) 5 → λ f· λ x· f(f(f(f(f(x)))))
  • 124. _0 = f => x => x _1 = f => x => f(x) _2 = f => x => f(f(x)) _3 = f => x => f(f(f(x))) _4 = f => x => f(f(f(f(x)))) _5 = f => x => f(f(f(f(f(x)))
  • 125. _0
  • 126. _0(n => n + 1)
  • 127. _0(n => n + 1)(0) _1(n => n + 1)(0) _2(n => n + 1)(0) _3(n => n + 1)(0) _4(n => n + 1)(0) _5(n => n + 1)(0) 0 1 2 3 4 5
  • 128. _0(n => n + ‘1’)(‘’) _1(n => n + ‘1’)(‘’) _2(n => n + ‘1’)(‘’) _3(n => n + ‘1’)(‘’) _4(n => n + ‘1’)(‘’) _5(n => n + ‘1’)(‘’) 1 11 111 1111 11111
  • 129. square
  • 130. square = m => _2(m)
  • 133. square(_7)(n => n + 1)(0)
  • 134. 49
  • 135.
  • 137. true → λ a b· a false → λ a b· b
  • 138.
  • 139. 7 * 7 < limit ifTrue: [^ ‘👍’] ifFalse: [^ ‘👎’]
  • 140. True ifTrue: toDo ifFalse: ignore ^ toDo value
  • 141. False ifTrue: ignore ifFalse: toDo ^ toDo value
  • 142. false → λ a b· b
  • 143. false → λ 🙂☹· ☹️
  • 144. false → λ f x· x
  • 146.
  • 147. pair → λ x y f· f(x)(y) first → λ p· p(λ x y· x) second → λ p· p(λ x y· y)
  • 148. pair → λ x y f· f x y first → λ p· p true second → λ p· p false nil → λ x· true
  • 149. cons → λ x y f· f x y car → λ p· p true cdr → λ p· p false nil → λ x· true
  • 150.
  • 152. def fizzbuzz(n) { result = '' if (n % 3 == 0) result += 'Fizz' if (n % 5 == 0) result += 'Buzz' if (!result) result += n result }
  • 153. The default action is executed only if some previous actions were not executed. Maciej Piróg “FizzBuzz in Haskell by Embedding a Domain-Specific Language”
  • 154. def fizzbuzz(n) { [0: 'Fizz'].get(n % 3, '') + [0: 'Buzz'].get(n % 5, '') ?: n.toString() }
  • 155. The default action is executed only if some previous actions were not executed. We ask if we can accomplish this without having to check the conditions for the previous actions twice. Maciej Piróg “FizzBuzz in Haskell by Embedding a Domain-Specific Language”
  • 156. def fizzbuzz(n) { if (n % 15 == 0) 'FizzBuzz' else if (n % 3 == 0) 'Fizz' else if (n % 5 == 0) 'Buzz' else n.toString() }
  • 157. def fizzbuzz(n) { if (n % 3 == 0 && n % 5 == 0) 'FizzBuzz' else if (n % 3 == 0) 'Fizz' else if (n % 5 == 0) 'Buzz' else n.toString() }
  • 158. The default action is executed only if some previous actions were not executed. We ask if we can accomplish this without having to check the conditions for the previous actions twice; in other words, if we can make the control flow follow the information flow without loosing modularity. Maciej Piróg “FizzBuzz in Haskell by Embedding a Domain-Specific Language”
  • 159. def fizzbuzz(n) { id = {x -> x} }
  • 160. def fizzbuzz(n) { id = {it} val = {x -> {_ -> x}} }
  • 161. def fizzbuzz(n) { id = {it} val = {{_ -> it}} fizz = n % 3 ? id : {val('Fizz' + it(''))} buzz = n % 5 ? id : {val('Buzz' + it(''))} fizz(buzz({it.toString()}))(n) }
  • 164.
  • 165. I have yet to see any problem, however complicated, which, when you looked at it in the right way, did not become still more complicated. Anderson's Law
  • 166.
  • 167.
  • 168. We shall not cease from exploration And the end of all our exploring Will be to arrive where we started And know the place for the first time. T S Eliot