SlideShare ist ein Scribd-Unternehmen logo
1 von 170
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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?
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 

Kürzlich hochgeladen (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 

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