SlideShare a Scribd company logo
1 of 93
Download to read offline
Why Functional
Programming Matters
John Hughes
Mary Sheeran
Functional Programming à la 1940s
• Minimalist: who needs booleans?
• A boolean just makes a choice!
• We can define if-then-else!
ifte bool t e =
bool t e
true
false
true x y =
false x y =
true x y = x
false x y = y
Who needs integers?
• A (positive) integer just counts loop iterations!
• To recover a ”normal” integer…
two f x = f (f x)
one f x = f x
zero f x = x
*Church> two (+1) 0
2
Look, Ma, we can add!
• Addition by sequencing loops
• Multiplication by nesting loops!
add m n f x = m f (n f x)
mul m n f x = m (n f) x
*Church> add one (mul two two) (+1) 0
5
m
n
mn
Factorial à la 1940
fact n =
ifte (iszero n)
one
(mul n (fact (decr n)))
*Church> fact (add one (mul two two)) (+1) 0
120
A couple more auxiliaries
• Testing for zero
• Decrementing…
iszero n =
n (_ -> false) true
decr n =
n (m f x-> f (m incr zero))
zero
(x->x)
zero
Booleans, integers, (and other
data structures) can be entirely
replaced by functions!
Alonzo Church
”Church encodings”
Early versions of the Glasgow
Haskell compiler actually
implemented data-structures
this way!
Before you try this at home…
Church.hs:27:35:
Occurs check: cannot construct the infinite type:
t ~ t -> t -> t
Expected type:
(((((t -> t -> t) -> t -> t)
-> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t
Actual type:(((((t -> t -> t) -> t -> t)
-> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> (((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t
But wait, there’s more…
Relevant bindings includen :: (((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> (((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t
(bound at Church.hs:27:6)
fact :: ((((((t -> t -> t) -> t -> t)
-> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> (((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> (((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t)
-> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t)
-> ((t -> t -> t) -> t -> t)
-> (t -> t -> t)
-> t
-> t
-> t
(bound at Church.hs:27:1)
In the first argument of ‘mul’, namely ‘n’
In the third argument of ‘ifte’, namely ‘(mul n (fact (decr n)))’
The type-checker needs a little bit
of help
fact ::
(forall a. (a->a)->a->a) ->
(a->a) -> a -> a
Factorial à la 1960
Higher-order functions!
(LABEL FACT (LAMBDA (N)
(COND ((ZEROP N) 1)
(T (TIMES N (FACT (SUB1 N)))))))
(MAPLIST FACT (QUOTE (1 2 3 4 5)))
(1 2 6 24 120)
Factorial in ISWIM
fac(5)
where rec fac(n) =
(n=1)  1;
n*fac(n-1)
Laws
(MAPLIST F (REVERSE L)) (REVERSE (MAPLIST F L))≡
What’s the point of two
different ways to do the
same thing?
Wouldn’t two facilities be
better than one?
Expressive power should
be by design, rather
than by accident!
Turing award 1977
Paper 1978
Conventional programming
languages are growing ever
more enormous,
but not stronger.
Inherent defects at the most
basic level cause them to be
both fat and weak:
Word-at-a-time
their inability to effectively use
powerful combining forms
for building new programs from
existing ones
apply to all
αf
construction
[f1,f2,f3,f4]
their lack of useful
mathematical properties for
reasoning about programs
[f1,f2,…,fn]  g
[f1g,f2g,…,fng]
[f1,f2,…,fn]  g
c := 0;
for i := 1 step 1 until n do
c := c + a[i] × b[i]
Def ScalarProduct =
(Insert +)  (ApplyToAll ×)  Transpose
Def SP = (/ +)  (α ×)  Trans
Peter Henderson, Functional Geometry, 1982
fish
over (fish, rot (rot (fish))
t = over (fish, over (fish2, fish3))
fish2 = flip (rot45 fish)
fish3 = rot (rot (rot (fish2)))
u = over (over (fish2, rot (fish2)),
over (rot (rot (fish2)),
rot (rot (rot (fish2)))))
P Q
R S
R
R
R
R
quartet cycle
v = cycle (rot(t)) quartet (v,v,v,v)
quartet(nil, nil,
rot(t), t)
quartet(side1,side1,
rot(t), t )
side1
quartet (nil,nil,nil,u) quartet(corner1,
side1,
rot(side1),
u)corner1
squarelimit = nonet(
corner, side, rot(rot(rot(corner))),
rot(side), u, rot(rot(rot(side))),
rot(corner), rot(rot(side)), rot(rot(corner)))
picture = function
picture = function
a
b
c
over (p,q) (a,b,c) =
p(a,b,c) U q(a,b,c)
over (p,q) (a,b,c) =
p(a,b,c) U q(a,b,c)
beside (p,q) (a,b,c) =
p(a,b/2,c) U q(a+b/2,b/2,c)
a
b
c
over (p,q) (a,b,c) =
p(a,b,c) U q(a,b,c)
beside (p,q) (a,b,c) =
p(a,b/2,c) U q(a+b/2,b/2,c)
a
b/2
c
b/2
c
rot(p) (a,b,c) = p(a+b,c,-b)
a
b
c
a+b
c
-b
Laws
rot(above(p,q))
=
beside(rot(p),rot(q))
It seems there is a positive correlation between
the simplicity of the rules and the quality of the
algebra as a description tool.
Whole values
Combining forms
Algebra as litmus test
Whole values
Combining forms
Algebra as litmus test
functions as
representations
The Problem: 2D Geo-server
Functions as Data
Including 29 lines of
inferable type
signatures/synonyms
A student, given 8 days
to learn Haskell, w/o
knowledge of Yale group
Reaction…
”too cute for its own good”
…higher-order functions just a trick, probably not useful in
other contexts
Lazy Evaluation (1976)
Henderson and Morris
A lazy evaluator
Friedman and Wise
CONS should not evaluate
its arguments
”The Whole Value” can be ∞!
• The infinite list of natural numbers
[0, 1, 2, 3 …]
• All the iterations of a function
iterate f x = [x, f x, f (f x), …]
• A consumer for numerical methods
limit eps xs =
<first element of xs within eps of its predecessor>
Consumer decides
how many to
compute
Some numerical algorithms
• Newton-Raphson square root
sqrt a = limit eps (iterate next 1.0)
where next x = (x + a/x) / 2
• Derivatives
deriv f x =
limit eps (map slope (iterate (/2) 1.0))
where slope h = (f (x+h) – f x) / h
Same convergence check Different approximation sequences
[1, 1/2, 1/4, 1/8…]
Speeding up convergence
Differentiation Integration
The smaller h is, the better
the approximation
A + B*hnThe right
answer
An error term
Eliminating the error term
• Given:
• Solve for A and B!
A + B*hn
A + B*(h/2)n
improve n xs converges faster than xs
Two successive
approximations
Really fast derivative
deriv f x =
limit eps
(improve 2
(improve 1
(map slope (iterate (/2) 1.0))))
The approximations
The improvements
The convergence check
Everything is programmed separately and easy to
understand—thanks to ”whole value programming”
1990
Lazy producer-consumer
consumer producer
demands
values
Convergence
test
Numerical
approximations
demands
values
Lazy producer-consumer
consumer producer
demands
values
Search
strategy
Search
space
demands
values
α
β
demands
values
prop_reverse() ->
?FORALL(Xs,list(int()),
reverse(reverse(Xs)) == Xs).
3> eqc:quickcheck(qc:prop_reverse()).
.....................................................
...............................................
OK, passed 100 tests
true
2000
prop_wrong() ->
?FORALL(Xs,list(int()),
reverse(Xs) == Xs).
4> eqc:quickcheck(qc:prop_wrong()).
Failed! After 1 tests.
[-36,-29,20,31,-47,-63,80,-7,93,-87,-29,33,64,58]
Shrinking xx.x.x..xx(4 times)
[0,1]
false minimal counterexample
Space of all
possible testsQuickCheck
search
strategy
random
systematic
muFP—Circuits as values
•Backus FP + one-clock-cycle delays
•Inherits many combining forms and
laws
•Good for reasoning about alternative
designs
Example law: “retiming”
=
Users!
Plessey video motion estimation
“Using muFP, the array processing element was
described in just one line of code and the complete
array required four lines of muFP description.
muFP enabled the effects of adding or moving data
latches within the array to be assessed quickly.”
Bhandal et al, An array processor for video picture motion estimation,
Systolic Array Processors, 1990, Prentice Hall
work with Plessey done by G. Jones and W. Luk
Lava
muFP + Functional Geometry
Capture semantics of a circuit +
relative placement
Programmer control of geometry!
 FPGA layouts on Xilinx chips
Satnam Singh
at Xilinx
Four adder trees from Lava
From VHDL, without layout info
Lava was implemented as a Haskell library
Satnam gave Xilinx customers Haskell binaries
Here’s a layout generator
for your problem
(Don’t ask what’s inside)
Intel
4195835.0 - 3145727.0*(4195835.0/3145727.0) = 0
Intel
4195835.0 - 3145727.0*(4195835.0/3145727.0) = 0
Flawed Pentium
4195835.0 - 3145727.0*(4195835.0/3145727.0) = 256
$475 million
Intel
fl —lazy functional language
built-in decision procedures
HW symbolic simulator
Forte System 1000s users
Thanks to Carl Seger (Intel)
fl
• Design
• High-level specification
• Scripting
• Implementation of formal verification
tools and theorem provers
• Object language for theorem proving
Thanks to Carl Seger (Intel)
Bluespec—FP for hardware
Haskell-like language (architecture)
+
Atomic transition rules (H/W modelling)
Verilog for further synthesis
Compiler finds
parallelism
Bluespec
Often BEATS hand-coded RTL code
Frees designers to use better algorithms
Refinement, evolution, major architectural change EASY
Types, Functional Programming and
Atomic Transactions in Hardware Design
Rishiyur Nikhil LNCS 8000
Bluecheck
•QuickCheck in Bluespec!
•Generates and shrinks tests on the chip!
A Generic Synthesisable Test Bench (Naylor and Moore,
Memocode 2015)
two f x = f (f x)
one f x = f x
zero f x = x
Why Functional Programming Matters by John Hughes

More Related Content

Viewers also liked

The Limited Red Society
The Limited Red SocietyThe Limited Red Society
The Limited Red SocietyNaresh Jain
 
Our Journey Down the Yellow Brick Road (Agile Adoption @ Directi)
Our Journey Down the Yellow Brick Road (Agile Adoption @ Directi)Our Journey Down the Yellow Brick Road (Agile Adoption @ Directi)
Our Journey Down the Yellow Brick Road (Agile Adoption @ Directi)Directi Group
 
Refactoring Fest
Refactoring FestRefactoring Fest
Refactoring FestNaresh Jain
 
Distributed Agile
Distributed AgileDistributed Agile
Distributed AgileNaresh Jain
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentNaresh Jain
 
Agile Maintenance
Agile MaintenanceAgile Maintenance
Agile MaintenanceNaresh Jain
 
Evolution Of Team Interaction Models
Evolution Of Team Interaction ModelsEvolution Of Team Interaction Models
Evolution Of Team Interaction ModelsNaresh Jain
 
Continuous Deployment Demystified
Continuous Deployment DemystifiedContinuous Deployment Demystified
Continuous Deployment DemystifiedNaresh Jain
 
Software Development The Trekkers Way
Software Development The Trekkers WaySoftware Development The Trekkers Way
Software Development The Trekkers WayNaresh Jain
 
ATDD - Acceptance Test Driven Development
ATDD - Acceptance Test Driven DevelopmentATDD - Acceptance Test Driven Development
ATDD - Acceptance Test Driven DevelopmentNaresh Jain
 
Agile Is the New Waterfall
Agile Is the New WaterfallAgile Is the New Waterfall
Agile Is the New WaterfallNaresh Jain
 
Design Thinking and Agile?
Design Thinking and Agile?Design Thinking and Agile?
Design Thinking and Agile?Tathagat Varma
 
Discovering functional treasure in idiomatic Groovy
Discovering functional treasure in idiomatic GroovyDiscovering functional treasure in idiomatic Groovy
Discovering functional treasure in idiomatic GroovyNaresha K
 
Unleashing the Power of Automated Refactoring with JDT
Unleashing the Power of Automated Refactoring with JDTUnleashing the Power of Automated Refactoring with JDT
Unleashing the Power of Automated Refactoring with JDTNaresh Jain
 
Functional Programming Conference 2016
Functional Programming Conference 2016Functional Programming Conference 2016
Functional Programming Conference 2016Naresh Jain
 
Towards FutureOps: Stable, Repeatable environments from Dev to Prod
Towards FutureOps: Stable, Repeatable environments from Dev to ProdTowards FutureOps: Stable, Repeatable environments from Dev to Prod
Towards FutureOps: Stable, Repeatable environments from Dev to ProdNaresh Jain
 

Viewers also liked (19)

The Limited Red Society
The Limited Red SocietyThe Limited Red Society
The Limited Red Society
 
Our Journey Down the Yellow Brick Road (Agile Adoption @ Directi)
Our Journey Down the Yellow Brick Road (Agile Adoption @ Directi)Our Journey Down the Yellow Brick Road (Agile Adoption @ Directi)
Our Journey Down the Yellow Brick Road (Agile Adoption @ Directi)
 
Refactoring Fest
Refactoring FestRefactoring Fest
Refactoring Fest
 
Distributed Agile
Distributed AgileDistributed Agile
Distributed Agile
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Agile Maintenance
Agile MaintenanceAgile Maintenance
Agile Maintenance
 
Evolution Of Team Interaction Models
Evolution Of Team Interaction ModelsEvolution Of Team Interaction Models
Evolution Of Team Interaction Models
 
Continuous Deployment Demystified
Continuous Deployment DemystifiedContinuous Deployment Demystified
Continuous Deployment Demystified
 
Software Development The Trekkers Way
Software Development The Trekkers WaySoftware Development The Trekkers Way
Software Development The Trekkers Way
 
MVP Hacks
MVP HacksMVP Hacks
MVP Hacks
 
ATDD - Acceptance Test Driven Development
ATDD - Acceptance Test Driven DevelopmentATDD - Acceptance Test Driven Development
ATDD - Acceptance Test Driven Development
 
Agile Testing
Agile TestingAgile Testing
Agile Testing
 
Agile Is the New Waterfall
Agile Is the New WaterfallAgile Is the New Waterfall
Agile Is the New Waterfall
 
Design Thinking and Agile?
Design Thinking and Agile?Design Thinking and Agile?
Design Thinking and Agile?
 
Discovering functional treasure in idiomatic Groovy
Discovering functional treasure in idiomatic GroovyDiscovering functional treasure in idiomatic Groovy
Discovering functional treasure in idiomatic Groovy
 
Unleashing the Power of Automated Refactoring with JDT
Unleashing the Power of Automated Refactoring with JDTUnleashing the Power of Automated Refactoring with JDT
Unleashing the Power of Automated Refactoring with JDT
 
The Eclipse Way
The Eclipse WayThe Eclipse Way
The Eclipse Way
 
Functional Programming Conference 2016
Functional Programming Conference 2016Functional Programming Conference 2016
Functional Programming Conference 2016
 
Towards FutureOps: Stable, Repeatable environments from Dev to Prod
Towards FutureOps: Stable, Repeatable environments from Dev to ProdTowards FutureOps: Stable, Repeatable environments from Dev to Prod
Towards FutureOps: Stable, Repeatable environments from Dev to Prod
 

More from Naresh Jain

Problem Solving Techniques For Evolutionary Design
Problem Solving Techniques For Evolutionary DesignProblem Solving Techniques For Evolutionary Design
Problem Solving Techniques For Evolutionary DesignNaresh Jain
 
Agile India 2019 Conference Welcome Note
Agile India 2019 Conference Welcome NoteAgile India 2019 Conference Welcome Note
Agile India 2019 Conference Welcome NoteNaresh Jain
 
Organizational Resilience
Organizational ResilienceOrganizational Resilience
Organizational ResilienceNaresh Jain
 
Improving the Quality of Incoming Code
Improving the Quality of Incoming CodeImproving the Quality of Incoming Code
Improving the Quality of Incoming CodeNaresh Jain
 
Agile India 2018 Conference Summary
Agile India 2018 Conference SummaryAgile India 2018 Conference Summary
Agile India 2018 Conference SummaryNaresh Jain
 
Agile India 2018 Conference
Agile India 2018 ConferenceAgile India 2018 Conference
Agile India 2018 ConferenceNaresh Jain
 
Agile India 2018 Conference
Agile India 2018 ConferenceAgile India 2018 Conference
Agile India 2018 ConferenceNaresh Jain
 
Agile India 2018 Conference
Agile India 2018 ConferenceAgile India 2018 Conference
Agile India 2018 ConferenceNaresh Jain
 
Pilgrim's Progress to the Promised Land by Robert Virding
Pilgrim's Progress to the Promised Land by Robert VirdingPilgrim's Progress to the Promised Land by Robert Virding
Pilgrim's Progress to the Promised Land by Robert VirdingNaresh Jain
 
Concurrent languages are Functional by Francesco Cesarini
Concurrent languages are Functional by Francesco CesariniConcurrent languages are Functional by Francesco Cesarini
Concurrent languages are Functional by Francesco CesariniNaresh Jain
 
Erlang from behing the trenches by Francesco Cesarini
Erlang from behing the trenches by Francesco CesariniErlang from behing the trenches by Francesco Cesarini
Erlang from behing the trenches by Francesco CesariniNaresh Jain
 
Anatomy of an eCommerce Search Engine by Mayur Datar
Anatomy of an eCommerce Search Engine by Mayur DatarAnatomy of an eCommerce Search Engine by Mayur Datar
Anatomy of an eCommerce Search Engine by Mayur DatarNaresh Jain
 
Setting up Continuous Delivery Culture for a Large Scale Mobile App
Setting up Continuous Delivery Culture for a Large Scale Mobile AppSetting up Continuous Delivery Culture for a Large Scale Mobile App
Setting up Continuous Delivery Culture for a Large Scale Mobile AppNaresh Jain
 
Value Driven Development by Dave Thomas
Value Driven Development by Dave Thomas Value Driven Development by Dave Thomas
Value Driven Development by Dave Thomas Naresh Jain
 
No Silver Bullets in Functional Programming by Brian McKenna
No Silver Bullets in Functional Programming by Brian McKennaNo Silver Bullets in Functional Programming by Brian McKenna
No Silver Bullets in Functional Programming by Brian McKennaNaresh Jain
 
Getting2Alpha: Turbo-charge your product with Game Thinking by Amy Jo Kim
Getting2Alpha: Turbo-charge your product with Game Thinking by Amy Jo KimGetting2Alpha: Turbo-charge your product with Game Thinking by Amy Jo Kim
Getting2Alpha: Turbo-charge your product with Game Thinking by Amy Jo KimNaresh Jain
 
MVP Design Hacks
MVP Design HacksMVP Design Hacks
MVP Design HacksNaresh Jain
 
Functional Conf 2015
Functional Conf 2015Functional Conf 2015
Functional Conf 2015Naresh Jain
 
Agile India 2016 Conference
Agile India 2016 ConferenceAgile India 2016 Conference
Agile India 2016 ConferenceNaresh Jain
 
Test Driving a jQuery Plugin
Test Driving a jQuery PluginTest Driving a jQuery Plugin
Test Driving a jQuery PluginNaresh Jain
 

More from Naresh Jain (20)

Problem Solving Techniques For Evolutionary Design
Problem Solving Techniques For Evolutionary DesignProblem Solving Techniques For Evolutionary Design
Problem Solving Techniques For Evolutionary Design
 
Agile India 2019 Conference Welcome Note
Agile India 2019 Conference Welcome NoteAgile India 2019 Conference Welcome Note
Agile India 2019 Conference Welcome Note
 
Organizational Resilience
Organizational ResilienceOrganizational Resilience
Organizational Resilience
 
Improving the Quality of Incoming Code
Improving the Quality of Incoming CodeImproving the Quality of Incoming Code
Improving the Quality of Incoming Code
 
Agile India 2018 Conference Summary
Agile India 2018 Conference SummaryAgile India 2018 Conference Summary
Agile India 2018 Conference Summary
 
Agile India 2018 Conference
Agile India 2018 ConferenceAgile India 2018 Conference
Agile India 2018 Conference
 
Agile India 2018 Conference
Agile India 2018 ConferenceAgile India 2018 Conference
Agile India 2018 Conference
 
Agile India 2018 Conference
Agile India 2018 ConferenceAgile India 2018 Conference
Agile India 2018 Conference
 
Pilgrim's Progress to the Promised Land by Robert Virding
Pilgrim's Progress to the Promised Land by Robert VirdingPilgrim's Progress to the Promised Land by Robert Virding
Pilgrim's Progress to the Promised Land by Robert Virding
 
Concurrent languages are Functional by Francesco Cesarini
Concurrent languages are Functional by Francesco CesariniConcurrent languages are Functional by Francesco Cesarini
Concurrent languages are Functional by Francesco Cesarini
 
Erlang from behing the trenches by Francesco Cesarini
Erlang from behing the trenches by Francesco CesariniErlang from behing the trenches by Francesco Cesarini
Erlang from behing the trenches by Francesco Cesarini
 
Anatomy of an eCommerce Search Engine by Mayur Datar
Anatomy of an eCommerce Search Engine by Mayur DatarAnatomy of an eCommerce Search Engine by Mayur Datar
Anatomy of an eCommerce Search Engine by Mayur Datar
 
Setting up Continuous Delivery Culture for a Large Scale Mobile App
Setting up Continuous Delivery Culture for a Large Scale Mobile AppSetting up Continuous Delivery Culture for a Large Scale Mobile App
Setting up Continuous Delivery Culture for a Large Scale Mobile App
 
Value Driven Development by Dave Thomas
Value Driven Development by Dave Thomas Value Driven Development by Dave Thomas
Value Driven Development by Dave Thomas
 
No Silver Bullets in Functional Programming by Brian McKenna
No Silver Bullets in Functional Programming by Brian McKennaNo Silver Bullets in Functional Programming by Brian McKenna
No Silver Bullets in Functional Programming by Brian McKenna
 
Getting2Alpha: Turbo-charge your product with Game Thinking by Amy Jo Kim
Getting2Alpha: Turbo-charge your product with Game Thinking by Amy Jo KimGetting2Alpha: Turbo-charge your product with Game Thinking by Amy Jo Kim
Getting2Alpha: Turbo-charge your product with Game Thinking by Amy Jo Kim
 
MVP Design Hacks
MVP Design HacksMVP Design Hacks
MVP Design Hacks
 
Functional Conf 2015
Functional Conf 2015Functional Conf 2015
Functional Conf 2015
 
Agile India 2016 Conference
Agile India 2016 ConferenceAgile India 2016 Conference
Agile India 2016 Conference
 
Test Driving a jQuery Plugin
Test Driving a jQuery PluginTest Driving a jQuery Plugin
Test Driving a jQuery Plugin
 

Recently uploaded

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
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
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
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
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
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
 
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
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
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
 
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.
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Recently uploaded (20)

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
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
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
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
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
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
 
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
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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
 
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 ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Why Functional Programming Matters by John Hughes

  • 2.
  • 3. Functional Programming à la 1940s • Minimalist: who needs booleans? • A boolean just makes a choice! • We can define if-then-else! ifte bool t e = bool t e true false true x y = false x y = true x y = x false x y = y
  • 4. Who needs integers? • A (positive) integer just counts loop iterations! • To recover a ”normal” integer… two f x = f (f x) one f x = f x zero f x = x *Church> two (+1) 0 2
  • 5. Look, Ma, we can add! • Addition by sequencing loops • Multiplication by nesting loops! add m n f x = m f (n f x) mul m n f x = m (n f) x *Church> add one (mul two two) (+1) 0 5 m n mn
  • 6. Factorial à la 1940 fact n = ifte (iszero n) one (mul n (fact (decr n))) *Church> fact (add one (mul two two)) (+1) 0 120
  • 7. A couple more auxiliaries • Testing for zero • Decrementing… iszero n = n (_ -> false) true decr n = n (m f x-> f (m incr zero)) zero (x->x) zero
  • 8. Booleans, integers, (and other data structures) can be entirely replaced by functions! Alonzo Church ”Church encodings” Early versions of the Glasgow Haskell compiler actually implemented data-structures this way!
  • 9. Before you try this at home… Church.hs:27:35: Occurs check: cannot construct the infinite type: t ~ t -> t -> t Expected type: (((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t Actual type:(((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t
  • 10. But wait, there’s more… Relevant bindings includen :: (((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t (bound at Church.hs:27:6) fact :: ((((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> (((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t) -> ((t -> t -> t) -> t -> t) -> (t -> t -> t) -> t -> t -> t (bound at Church.hs:27:1) In the first argument of ‘mul’, namely ‘n’ In the third argument of ‘ifte’, namely ‘(mul n (fact (decr n)))’
  • 11. The type-checker needs a little bit of help fact :: (forall a. (a->a)->a->a) -> (a->a) -> a -> a
  • 12. Factorial à la 1960 Higher-order functions! (LABEL FACT (LAMBDA (N) (COND ((ZEROP N) 1) (T (TIMES N (FACT (SUB1 N))))))) (MAPLIST FACT (QUOTE (1 2 3 4 5))) (1 2 6 24 120)
  • 13. Factorial in ISWIM fac(5) where rec fac(n) = (n=1)  1; n*fac(n-1)
  • 14. Laws (MAPLIST F (REVERSE L)) (REVERSE (MAPLIST F L))≡ What’s the point of two different ways to do the same thing? Wouldn’t two facilities be better than one? Expressive power should be by design, rather than by accident!
  • 16. Conventional programming languages are growing ever more enormous, but not stronger.
  • 17. Inherent defects at the most basic level cause them to be both fat and weak:
  • 19. their inability to effectively use powerful combining forms for building new programs from existing ones
  • 20.
  • 23. their lack of useful mathematical properties for reasoning about programs
  • 26. c := 0; for i := 1 step 1 until n do c := c + a[i] × b[i]
  • 27. Def ScalarProduct = (Insert +)  (ApplyToAll ×)  Transpose
  • 28. Def SP = (/ +)  (α ×)  Trans
  • 29. Peter Henderson, Functional Geometry, 1982
  • 30. fish
  • 31. over (fish, rot (rot (fish))
  • 32. t = over (fish, over (fish2, fish3)) fish2 = flip (rot45 fish) fish3 = rot (rot (rot (fish2)))
  • 33. u = over (over (fish2, rot (fish2)), over (rot (rot (fish2)), rot (rot (rot (fish2)))))
  • 35. v = cycle (rot(t)) quartet (v,v,v,v)
  • 38. squarelimit = nonet( corner, side, rot(rot(rot(corner))), rot(side), u, rot(rot(rot(side))), rot(corner), rot(rot(side)), rot(rot(corner)))
  • 39.
  • 42. over (p,q) (a,b,c) = p(a,b,c) U q(a,b,c)
  • 43. over (p,q) (a,b,c) = p(a,b,c) U q(a,b,c) beside (p,q) (a,b,c) = p(a,b/2,c) U q(a+b/2,b/2,c) a b c
  • 44. over (p,q) (a,b,c) = p(a,b,c) U q(a,b,c) beside (p,q) (a,b,c) = p(a,b/2,c) U q(a+b/2,b/2,c) a b/2 c b/2 c
  • 45. rot(p) (a,b,c) = p(a+b,c,-b) a b c a+b c -b
  • 46. Laws rot(above(p,q)) = beside(rot(p),rot(q)) It seems there is a positive correlation between the simplicity of the rules and the quality of the algebra as a description tool.
  • 48. Whole values Combining forms Algebra as litmus test functions as representations
  • 49.
  • 50. The Problem: 2D Geo-server
  • 52. Including 29 lines of inferable type signatures/synonyms A student, given 8 days to learn Haskell, w/o knowledge of Yale group
  • 53. Reaction… ”too cute for its own good” …higher-order functions just a trick, probably not useful in other contexts
  • 54. Lazy Evaluation (1976) Henderson and Morris A lazy evaluator Friedman and Wise CONS should not evaluate its arguments
  • 55. ”The Whole Value” can be ∞! • The infinite list of natural numbers [0, 1, 2, 3 …] • All the iterations of a function iterate f x = [x, f x, f (f x), …] • A consumer for numerical methods limit eps xs = <first element of xs within eps of its predecessor> Consumer decides how many to compute
  • 56. Some numerical algorithms • Newton-Raphson square root sqrt a = limit eps (iterate next 1.0) where next x = (x + a/x) / 2 • Derivatives deriv f x = limit eps (map slope (iterate (/2) 1.0)) where slope h = (f (x+h) – f x) / h Same convergence check Different approximation sequences [1, 1/2, 1/4, 1/8…]
  • 57. Speeding up convergence Differentiation Integration The smaller h is, the better the approximation A + B*hnThe right answer An error term
  • 58. Eliminating the error term • Given: • Solve for A and B! A + B*hn A + B*(h/2)n improve n xs converges faster than xs Two successive approximations
  • 59. Really fast derivative deriv f x = limit eps (improve 2 (improve 1 (map slope (iterate (/2) 1.0)))) The approximations The improvements The convergence check Everything is programmed separately and easy to understand—thanks to ”whole value programming”
  • 60. 1990
  • 64. prop_reverse() -> ?FORALL(Xs,list(int()), reverse(reverse(Xs)) == Xs). 3> eqc:quickcheck(qc:prop_reverse()). ..................................................... ............................................... OK, passed 100 tests true 2000
  • 65. prop_wrong() -> ?FORALL(Xs,list(int()), reverse(Xs) == Xs). 4> eqc:quickcheck(qc:prop_wrong()). Failed! After 1 tests. [-36,-29,20,31,-47,-63,80,-7,93,-87,-29,33,64,58] Shrinking xx.x.x..xx(4 times) [0,1] false minimal counterexample
  • 66. Space of all possible testsQuickCheck search strategy random systematic
  • 67.
  • 68. muFP—Circuits as values •Backus FP + one-clock-cycle delays •Inherits many combining forms and laws •Good for reasoning about alternative designs
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79. Users! Plessey video motion estimation “Using muFP, the array processing element was described in just one line of code and the complete array required four lines of muFP description. muFP enabled the effects of adding or moving data latches within the array to be assessed quickly.” Bhandal et al, An array processor for video picture motion estimation, Systolic Array Processors, 1990, Prentice Hall work with Plessey done by G. Jones and W. Luk
  • 80. Lava muFP + Functional Geometry Capture semantics of a circuit + relative placement Programmer control of geometry!  FPGA layouts on Xilinx chips Satnam Singh at Xilinx
  • 81. Four adder trees from Lava
  • 82. From VHDL, without layout info
  • 83. Lava was implemented as a Haskell library Satnam gave Xilinx customers Haskell binaries Here’s a layout generator for your problem (Don’t ask what’s inside)
  • 85. Intel 4195835.0 - 3145727.0*(4195835.0/3145727.0) = 0 Flawed Pentium 4195835.0 - 3145727.0*(4195835.0/3145727.0) = 256
  • 87. Intel fl —lazy functional language built-in decision procedures HW symbolic simulator Forte System 1000s users Thanks to Carl Seger (Intel)
  • 88. fl • Design • High-level specification • Scripting • Implementation of formal verification tools and theorem provers • Object language for theorem proving Thanks to Carl Seger (Intel)
  • 89. Bluespec—FP for hardware Haskell-like language (architecture) + Atomic transition rules (H/W modelling) Verilog for further synthesis Compiler finds parallelism
  • 90. Bluespec Often BEATS hand-coded RTL code Frees designers to use better algorithms Refinement, evolution, major architectural change EASY Types, Functional Programming and Atomic Transactions in Hardware Design Rishiyur Nikhil LNCS 8000
  • 91. Bluecheck •QuickCheck in Bluespec! •Generates and shrinks tests on the chip! A Generic Synthesisable Test Bench (Naylor and Moore, Memocode 2015)
  • 92. two f x = f (f x) one f x = f x zero f x = x