SlideShare une entreprise Scribd logo
1  sur  45
Télécharger pour lire hors ligne
orb@nostacktrace.com




                           The Lambda Calculus
                       λ           and
                              The Javascript
Norman Richards
orb@nostacktrace.com

                                                   Why lambda calculus?

                                                                                                                     Alan TUring
                                             Alonzo CHURCh
                                                                                                              Invented the turing machine, an
                                       Created lambda calculus, the
                                                                                                                imperative computing model
                                     basis for functional programming.




                                                                                         We spend all our time
                                                                                       studying this guy’s work
                                                                                       (because he’s awesome)
Norman Richards




                       http://en.wikipedia.org/wiki/Alonzo_Church    But if we want to think functionally,                 http://en.wikipedia.org/wiki/Alan_Turing

                                                                    we should pay attention to this guy too
                                                                        (because he’s also awesome)
orb@nostacktrace.com
                                       The premise



                                    Functional programming is good

                         Using functional techniques will make your code better

                       Understanding lambda calculus will improve your functional
Norman Richards
orb@nostacktrace.com
                       A Lambda Expression


                           bound variable
                           This is the argument of
                                 the function



                                        λx.x
                                                             body
                                                A lambda expression that uses the
                                                bound variable and represents the
                                                         function value
Norman Richards
orb@nostacktrace.com
                        A Lambda Expression




                                     function(x) {
                       λx.x             return x
                                     }
Norman Richards
orb@nostacktrace.com
                       Not a Lambda Expression




                                λy.x
                                         free variable
                                   This variable isn’t bound, so this
                                      expression is meaningless
Norman Richards
orb@nostacktrace.com
                        A Lambda Expression




                                            function(y) {
                       λy.x                    return x
                                            }
Norman Richards




                               These are
                              meaningless
orb@nostacktrace.com
                       A Lambda Expression


                              parenthesis
                           Not needed, but used for
                                 clarity here



                                  λx.(λ.y.x)
                                                           bound or free?
                                                      x is bound in the outer expression
                                                         and free in inner expression.
Norman Richards
orb@nostacktrace.com
                           A Lambda Expression



                                       function(x) {
                                          return function(y) {
                       λx.λ.y.x               return x
                                          }
                                       }
Norman Richards
orb@nostacktrace.com
                            Lambda Application

                                                                    unicorns don’t exist
                                                            There are no assignments or external references.
                                                             We’ll use upper-case words to stand for some
                                                               valid lambda expression, but it must mean
                                                                              something.



                                          λx.x UNICORN
                       application by substitution

                         Apply UNICORN to the expression,
                          substituting UNICORN for every
                          occurrence of the bound value
Norman Richards
orb@nostacktrace.com
                                 Lambda Application

                          The I (identity) combinator
                       Combinatory logic predates lambda calculus, but
                         the models are quite similar. Many lambda
                        expressions are referred to by their equivalent
                                     combinator names.

                                                                          function(x) {
                       λx.x UNICORN                                          return x
                       ! UNICORN                                          }(UNICORN);

                                                                          ! UNICORN
Norman Richards
orb@nostacktrace.com
                                                 Lambda Application

                         the K (constant) combinator
                         This function takes an input argument and
                       returns a function that returns that same value




                          λx.λy.x UNICORN                                  λy.UNICORN MITT
                        ! λy.UNICORN                                     ! UNICORN
                                                                                always a UNICORN
Norman Richards




                                                                            No matter what argument is passed
                                                                             in, the result is always the same.




                                                                                   http://leftaction.com/action/ask-kansas-mitt-romney-unicorn
orb@nostacktrace.com
                                       Lambda Application


                          self-application
                       This function takes a function and
                               applies it to itself.

                                                            function(f) {
                          λs.(s s)                             return f(f);
                                                            }
Norman Richards
orb@nostacktrace.com
                                                   Lambda Application



                       Substitute λx.x for s   λs.(s s) λx.x             function(f) {
                                               ! λx.x λx.x                  return f(f);
                                                                         }(function (x) {
                                               ! λx1.x1 λx.x                return x;
                       For clarity,
                       rename x as x1          ! λx.x                      });
Norman Richards




                                                       Substitute λx.x
                                                       for x1.
orb@nostacktrace.com
                       Infinite application


                        λs.(s s) λs.(s s)
                        ! λs.(s s) λs.(s s)
                        ! λs.(s s) λs.(s s)
                        ! …
                               the halting problem
Norman Richards




                         Just as you’d expect, there’s no algorithm to
                          determine whether or not a given lambda
                                   expression will terminate
orb@nostacktrace.com
                       Turing Complete



                       I: λx.x
                       K: λx.λy.x
                       S: λx.λy.λz.x z (y z)
Norman Richards




                                               http://en.wikipedia.org/wiki/SKI_combinator_calculus
orb@nostacktrace.com
                       Actually, just two lambdas
                       S   K K UNICORN
                       !   λx.λy.λz.(x z (y z)) K K UNICORN
                       !   λy.λz.(K z (y z)) K UNICORN
                       !   λz.(K z (K z)) UNICORN
                       !   K UNICORN (K UNICORN)
                       !   λx.λy.x UNICORN (K UNICORN)
                       !   λy.UNICORN (K UNICORN)
Norman Richards




                       !   UNICORN   Thus, S K K is computationally
                                         equivalent to identity
orb@nostacktrace.com
                                  Other Turing Complete things
                                                       Magic: the Gathering

                                                        http://www.toothycat.net/
                                                            ~hologram/Turing/




                         C++ Templates                                                  The number 110
                       http://citeseerx.ist.psu.edu/
Norman Richards




                           viewdoc/summary?                                         http://mathworld.wolfram.com/
                            doi=10.1.1.14.3670                                               Rule110.html
orb@nostacktrace.com
                                      TURING TARPIT



                       Beware of the Turing tar-pit in which everything is
                           possible but nothing of interest is easy.

                                                                   Alan Perlis
Norman Richards




                                                                  http://pu.inf.uni-tuebingen.de/users/klaeren/epigrams.html
orb@nostacktrace.com
                                                                                 Currying
                                                                                       function(x) {
                                                                                         return function(y) {
                                                                                           return function (z) {
                       A function that returns a FUNCTION                                     return UNICORN;
                       .. that returns a function that returns a function. You
                         can think of this as a function of three arguments.               }
                       λx.λy.λz.UNICORN X Y Z                                            }
                                                                                       }(X)(Y)(Z);
Norman Richards




                                                                                       function(x,y,z) {
                                                                                          return UNICORN;
                                                                                       }(X,Y,Z);
orb@nostacktrace.com
                                   Currying

                         Sometimes abbreviated
                            Sometimes, you’ll see lambda
                        expressions written like this for clarity.
                           The arguments are still curried.



                       λx y z.UNICORN X Y Z
                                                                                      HASKELL CURRY
                       ! λy z.UNICORN Y Z                                     Curry studied combinatory logic, a
                                                                                 variant of lambda calculus.

                       ! λz.UNICORN Z
                       ! UNICORN
Norman Richards




                                                                     http://www.haskell.org/haskellwiki/Haskell_Brooks_Curry
orb@nostacktrace.com
                       data structures

                                CHURCH PAIR ENCODING
                         PAIR takes two arguments, x and y and returns
                           a function that takes another function and
                                      applies x and y to it.



                       PAIR: λx.λy.λf.(f x y)
                                       BuILDING UP STATE
                            PAIR takes two arguments, x and y and returns
                              a function that takes another function and
                                         applies x and y to it.
Norman Richards
orb@nostacktrace.com
                       data structures


                       PAIR:   λx.λy.λf.(f x y)
                       FIRST: λx.λy.x
                       SECOND: λx.λy.y

                                  ACCESSOR FUNCTIONS
                          FIRST and SECOND are functions that can be
Norman Richards




                          passed to pair. They take two arguments and
                             return the first and second, respectively.
orb@nostacktrace.com
                               data structures


                       PAIR:   λx.λy.λf.(f x y)

                       DOGCAT: PAIR DOG CAT
                               ! λx.λy.λf.(f x y) DOG CAT
                               ! λy.λf.(f DOG y) CAT
                               ! λf.(f DOG CAT)
Norman Richards
orb@nostacktrace.com
                        data structures

                       DOGCAT: λf.(f DOG CAT)
                       FIRST: λx.λy.x
                       SECOND: λx.λy.y

                       DOGCAT FIRST
                       ! λf.(f DOG CAT) λx.λy.x
                       ! λx.λy.x DOG CAT
Norman Richards




                       ! λy.DOG CAT
                       ! DOG
orb@nostacktrace.com
                         data structures

                       DOGCAT: λf.(f DOG CAT)
                       FIRST: λx.λy.x
                       SECOND: λx.λy.y

                       DOGCAT SECOND
                       ! λf.(f DOG CAT) λx.λy.x
                       ! λx.λy.x DOG CAT
Norman Richards




                       ! λy.y CAT
                       ! CAT
orb@nostacktrace.com
                              data structures

                       RGB:    λr.λg.λb.λf.(f r g b)

                       RED:   λr.λg.λb.r
                       GREEN: λr.λg.λb.g
                       BLUE: λr.λg.λb.b

                       BLACK_COLOR: RGB 255 255 255
Norman Richards




                       WHITE_COLOR: RGB 0 0 0
                                                      NuMBERS?
                                       We haven’t seen how to construct numbers yet,
                                          but for the moment imagine that we did.
orb@nostacktrace.com

                                             data structures
                                                                              AVERAGE?
                       AVG: λx.λy.???                                 If we did have numbers, we could
                                                                    probably do math like simple averaging



                       MIX_RGB:
                          λc1.λc2.λf.
                            (f (AVG (c1 RED) (c2 RED))
                                (AVG (c1 GREEN)(c2 GREEN))
                                (AVG (c1 BLUE) (c2 BLUE)))
Norman Richards




                                    OO LAMBDA?
                       MIX_RGB takes two colors and returns a new
                            color that is the mix of the two
orb@nostacktrace.com
                           CONDITIONALS


                        COND: λe1.λe2.λc.(c e1 e2)
                        TRUE: λx.λy.x
                       FALSE: λx.λy.y
                                        Look familiar?
                              Think of a boolean condition as a PAIR of
                             values. TRUE selects the first one and FALSE
                                       selects the second one.
Norman Richards
orb@nostacktrace.com
                                     CONDITIONALS
                         COND DEAD ALIVE QUBIT
                         ! λe1.λe2.λc.(c e1 e2) DEAD ALIVE QUBIT
                         ! QUBIT DEAD ALIVE



                       ! TRUE DEAD ALIVE          ! FALSE DEAD ALIVE
                       ! λx.λy.x DEAD ALIVE       ! λx.λy.y DEAD ALIVE
Norman Richards




                       ! DEAD                     ! ALIVE


                                                           https://www.coursera.org/course/qcomp
orb@nostacktrace.com
                            BOOLEAN LOGIC


                       NOT: λx.(COND FALSE TRUE x)
                       AND: λx.λy.(COND y FALSE x)
                        OR: λx.λy.(COND TRUE y x)
Norman Richards
orb@nostacktrace.com
                                                         NUMBERS
                       ZERO: λx.x
                       SUCC: λn.λs.(s false n)

                       ONE: SUCC ZERO
                            ! λs.(s false ZERO)
                       TWO: SUCC ONE
                            ! λs.(s false ONE)
                            ! λs.(s false λs.(s false ZERO))
Norman Richards




                              PEANO NUMBERS
                       PEANO numbers are based on a zero function
                               and a successor function
orb@nostacktrace.com
                                       NUMBERS



                                              ISZERO ZERO
                         ZERO: λx.x           ! λn.(n FIRST) λx.x
                       ISZERO: λn.(n FIRST)   ! λx.x FIRST
                                              ! FIRST
Norman Richards




                                              ! TRUE
orb@nostacktrace.com
                                NUMBERS

                         ISZERO: λn.(n FIRST)
                            ONE: λs.(s FALSE ZERO)


                       ISZERO ONE
                       ! λn.(n FIRST) λs.(s FALSE ZERO)
                       ! λs.(s FALSE ZERO) FIRST
                       ! (FIRST FALSE ZERO)
Norman Richards




                       ! FALSE
orb@nostacktrace.com
                                              NUMBERS

                       PRED: λn.(n SECOND)

                       PRED (SUCC NUM)
                       ! λn.(n SECOND) λs.(s FALSE NUM)
                       ! λs.(s FALSE ZERO) SECOND
                       ! SECOND FALSE NUM
                       ! NUM
Norman Richards




                                 but...
                       ZERO isn’t SUCC of a number
orb@nostacktrace.com
                                 NUMBERS



                       PRED: λn.(ISZERO n) ZERO (n SECOND)
                                    What is Pred of zero?
                                    We can at least test for zero and
                                        return another number.
Norman Richards
orb@nostacktrace.com
                                                                    NUMBERS


                       ADD:λx.λy.(ISZERO Y)                                 function add(x,y) {
                           x                                                  if (y==0) {
                           (ADD (SUCC X)                                        return x
                                (PRED Y))                                     } else {
                                                                                return add(x+1,y-1)
                                           NOT VALID
                                Recursive definitions aren’t possible .        }
Norman Richards




                           Remember, names are just syntactics sugar. All
                            definitions must be finite. How do we do this?    }
orb@nostacktrace.com
                            RECURSION DIVERSION
                           If we could pass the function in
                           Now we’ll make a function of three arguments,
                             the first being the function to recurse on



                       ADD 1:λf.λx.λy.(ISZERO                                     Y)
                                   x
                                  (f f (SUCC X) (PRED Y))
                                  Then we could call it RECURSIVELY
                                    Just remember that the function takes three
Norman Richards




                                 arguments, so we should pass the function to itself.
orb@nostacktrace.com
                             RECURSION DIVERSION

                       ADD 1:λf.λx.λy.(ISZERO                           Y)
                                     x
                                    (f f (SUCC X) (PRED Y))

                       ADD:  ADD 1           ADD 1

                       ! λx.λy.(ISZERO Y)
                            x
Norman Richards




                            (ADD 1 ADD1 (SUCC X) (PRED Y))

                                  FINITE DEFINiTION
                           This definition of ADD is a bit repetitive,
                            but it doesn’t recurse infinitely. If only
                                we could clean this up a bit...
orb@nostacktrace.com
                          BEHOLD, the Y combinator
                          Y: λf.(λs.(f (s s)) (λs.(f (s s)))

                       ADD 1:   λf.λx.λy.(ISZERO Y) X
                                  (F (SUCC X) (PRED Y))

                       ADD: Y    ADD 1

                       ! λs.(ADD 1 (s s)) (λs.(ADD1 (s s))

                       ! ADD1 (λs.(ADD1 (s s)) λs.(ADD1 (s s)))
Norman Richards




                       ! ADD1 (Y ADD1)

                       ! ADD1 ADD      Y self replicates
                                         This is similar to the hand prior call, except that
                                          the replication state is in the passed function.
orb@nostacktrace.com
                         CHURCH NUMBERs

                       ZERO:    λf.λx.x
                       ONE:     λf.λx.f                x
                       TWO:     λf.λx.f                (f x)
                       THREE:   λf.λx.f                (f (f x))
                       FOUR:    λf.λx.f                (f (f (f x)))
                                repeated function application
Norman Richards




                                Church numbers take a function and an argument
                                 and apply the function to the argument n times.
                                   So N is defined by doing something N times.
orb@nostacktrace.com
                          CHURCH NUMBERs
                       ZERO:   λn.(n λx.FALSE TRUE)
                       SUCC:   λn.λf.λx.f (n f x)
                       ADD:    λm.λn.λf.λx.m f (n f x)
                       MUL:    λm.λn.λf.m (n f)
                       POW:    λm.λn.m n
                       PRED:   λn.λf.λx.n (λg.λh. h (g f))
                                       λu.x λu.u
Norman Richards




                                No recursion for simple math
                                  Church numbers have some very simple
                               operations, Operations like subtraction are more
                                       complex than Peano numbers.
orb@nostacktrace.com
                              And the rest is functional


                                                                 An introduction to
                                                              Functional Programming
                                                             Through Lambda Calculus

                                                                Greg Michaelson
Norman Richards




                       http://www.amazon.com/dp/0486478831
orb@nostacktrace.com
                                         Leisure
                                   https://github.com/zot/Leisure

                       •Lambda Calculus engine written in Javascript
                       •Intended for programming
                       •REPL environment with node.js
                       •Runs in the browser
Norman Richards




                                      http://tinyconcepts.com/invaders.html
orb@nostacktrace.com




                                          λ       thank you
Norman Richards




                       http://www.slideshare.net/normanrichards/the-lambda-calculus-and-the-javascript

Contenu connexe

Tendances

L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handlingteach4uin
 
Web topic 18 conflict resolution in css
Web topic 18  conflict resolution in cssWeb topic 18  conflict resolution in css
Web topic 18 conflict resolution in cssCK Yang
 
Visual Basic IDE Introduction
Visual Basic IDE IntroductionVisual Basic IDE Introduction
Visual Basic IDE IntroductionAhllen Javier
 
Java string handling
Java string handlingJava string handling
Java string handlingSalman Khan
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp PresentationVishwa Mohan
 
Introduction to c language | History of C language
Introduction to c language | History of C languageIntroduction to c language | History of C language
Introduction to c language | History of C languagesimplidigital
 
Let us c yashwant kanetkar(1)
Let us c   yashwant kanetkar(1)Let us c   yashwant kanetkar(1)
Let us c yashwant kanetkar(1)OMWOMA JACKSON
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programmingRiccardo Cardin
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Luzan Baral
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)Ravi_Kant_Sahu
 
CS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab ManualCS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab Manualpkaviya
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 

Tendances (20)

Java Basics
Java BasicsJava Basics
Java Basics
 
Java exception-handling
Java exception-handlingJava exception-handling
Java exception-handling
 
Sesiones en Php
Sesiones en  PhpSesiones en  Php
Sesiones en Php
 
L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handling
 
Web topic 18 conflict resolution in css
Web topic 18  conflict resolution in cssWeb topic 18  conflict resolution in css
Web topic 18 conflict resolution in css
 
Visual Basic IDE Introduction
Visual Basic IDE IntroductionVisual Basic IDE Introduction
Visual Basic IDE Introduction
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Java platform
Java platformJava platform
Java platform
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
 
Introduction to c language | History of C language
Introduction to c language | History of C languageIntroduction to c language | History of C language
Introduction to c language | History of C language
 
Let us c yashwant kanetkar(1)
Let us c   yashwant kanetkar(1)Let us c   yashwant kanetkar(1)
Let us c yashwant kanetkar(1)
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
jQuery
jQueryjQuery
jQuery
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
 
CS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab ManualCS8662 Mobile Application Development Lab Manual
CS8662 Mobile Application Development Lab Manual
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 

En vedette

Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming FundamentalsShahriar Hyder
 
Interactive Scientific Image Analysis using Spark
Interactive Scientific Image Analysis using SparkInteractive Scientific Image Analysis using Spark
Interactive Scientific Image Analysis using SparkKevin Mader
 
Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Hakka Labs
 
Machine Learning with Apache Mahout
Machine Learning with Apache MahoutMachine Learning with Apache Mahout
Machine Learning with Apache MahoutDaniel Glauser
 
Modeling with Hadoop kdd2011
Modeling with Hadoop kdd2011Modeling with Hadoop kdd2011
Modeling with Hadoop kdd2011Milind Bhandarkar
 
Functional programming
Functional programmingFunctional programming
Functional programmingedusmildo
 
Functional programming
Functional programmingFunctional programming
Functional programmingPrateek Jain
 
Functional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis AtencioFunctional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis AtencioLuis Atencio
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 
Predictive Analytics Project in Automotive Industry
Predictive Analytics Project in Automotive IndustryPredictive Analytics Project in Automotive Industry
Predictive Analytics Project in Automotive IndustryMatouš Havlena
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScripttmont
 

En vedette (11)

Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 
Interactive Scientific Image Analysis using Spark
Interactive Scientific Image Analysis using SparkInteractive Scientific Image Analysis using Spark
Interactive Scientific Image Analysis using Spark
 
Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey
 
Machine Learning with Apache Mahout
Machine Learning with Apache MahoutMachine Learning with Apache Mahout
Machine Learning with Apache Mahout
 
Modeling with Hadoop kdd2011
Modeling with Hadoop kdd2011Modeling with Hadoop kdd2011
Modeling with Hadoop kdd2011
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Functional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis AtencioFunctional Programming in JavaScript by Luis Atencio
Functional Programming in JavaScript by Luis Atencio
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Predictive Analytics Project in Automotive Industry
Predictive Analytics Project in Automotive IndustryPredictive Analytics Project in Automotive Industry
Predictive Analytics Project in Automotive Industry
 
Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
 

Plus de Norman Richards

An Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScriptAn Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScriptNorman Richards
 
Logic programming a ruby perspective
Logic programming a ruby perspectiveLogic programming a ruby perspective
Logic programming a ruby perspectiveNorman Richards
 
Lisp 1.5 - Running history
Lisp 1.5 - Running historyLisp 1.5 - Running history
Lisp 1.5 - Running historyNorman Richards
 
The Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unificationThe Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unificationNorman Richards
 
Deconstructing the Functional Web with Clojure
Deconstructing the Functional Web with ClojureDeconstructing the Functional Web with Clojure
Deconstructing the Functional Web with ClojureNorman Richards
 

Plus de Norman Richards (8)

An Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScriptAn Adventure in Serverless ClojureScript
An Adventure in Serverless ClojureScript
 
Logic programming a ruby perspective
Logic programming a ruby perspectiveLogic programming a ruby perspective
Logic programming a ruby perspective
 
Lisp 1.5 - Running history
Lisp 1.5 - Running historyLisp 1.5 - Running history
Lisp 1.5 - Running history
 
The Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unificationThe Logical Burrito - pattern matching, term rewriting and unification
The Logical Burrito - pattern matching, term rewriting and unification
 
Deconstructing the Functional Web with Clojure
Deconstructing the Functional Web with ClojureDeconstructing the Functional Web with Clojure
Deconstructing the Functional Web with Clojure
 
Immutant
ImmutantImmutant
Immutant
 
core.logic introduction
core.logic introductioncore.logic introduction
core.logic introduction
 
Vert.X mini-talk
Vert.X mini-talkVert.X mini-talk
Vert.X mini-talk
 

Dernier

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Dernier (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

The Lambda Calculus and The JavaScript

  • 1. orb@nostacktrace.com The Lambda Calculus λ and The Javascript Norman Richards
  • 2. orb@nostacktrace.com Why lambda calculus? Alan TUring Alonzo CHURCh Invented the turing machine, an Created lambda calculus, the imperative computing model basis for functional programming. We spend all our time studying this guy’s work (because he’s awesome) Norman Richards http://en.wikipedia.org/wiki/Alonzo_Church But if we want to think functionally, http://en.wikipedia.org/wiki/Alan_Turing we should pay attention to this guy too (because he’s also awesome)
  • 3. orb@nostacktrace.com The premise Functional programming is good Using functional techniques will make your code better Understanding lambda calculus will improve your functional Norman Richards
  • 4. orb@nostacktrace.com A Lambda Expression bound variable This is the argument of the function λx.x body A lambda expression that uses the bound variable and represents the function value Norman Richards
  • 5. orb@nostacktrace.com A Lambda Expression function(x) { λx.x return x } Norman Richards
  • 6. orb@nostacktrace.com Not a Lambda Expression λy.x free variable This variable isn’t bound, so this expression is meaningless Norman Richards
  • 7. orb@nostacktrace.com A Lambda Expression function(y) { λy.x return x } Norman Richards These are meaningless
  • 8. orb@nostacktrace.com A Lambda Expression parenthesis Not needed, but used for clarity here λx.(λ.y.x) bound or free? x is bound in the outer expression and free in inner expression. Norman Richards
  • 9. orb@nostacktrace.com A Lambda Expression function(x) { return function(y) { λx.λ.y.x return x } } Norman Richards
  • 10. orb@nostacktrace.com Lambda Application unicorns don’t exist There are no assignments or external references. We’ll use upper-case words to stand for some valid lambda expression, but it must mean something. λx.x UNICORN application by substitution Apply UNICORN to the expression, substituting UNICORN for every occurrence of the bound value Norman Richards
  • 11. orb@nostacktrace.com Lambda Application The I (identity) combinator Combinatory logic predates lambda calculus, but the models are quite similar. Many lambda expressions are referred to by their equivalent combinator names. function(x) { λx.x UNICORN return x ! UNICORN }(UNICORN); ! UNICORN Norman Richards
  • 12. orb@nostacktrace.com Lambda Application the K (constant) combinator This function takes an input argument and returns a function that returns that same value λx.λy.x UNICORN λy.UNICORN MITT ! λy.UNICORN ! UNICORN always a UNICORN Norman Richards No matter what argument is passed in, the result is always the same. http://leftaction.com/action/ask-kansas-mitt-romney-unicorn
  • 13. orb@nostacktrace.com Lambda Application self-application This function takes a function and applies it to itself. function(f) { λs.(s s) return f(f); } Norman Richards
  • 14. orb@nostacktrace.com Lambda Application Substitute λx.x for s λs.(s s) λx.x function(f) { ! λx.x λx.x return f(f); }(function (x) { ! λx1.x1 λx.x return x; For clarity, rename x as x1 ! λx.x }); Norman Richards Substitute λx.x for x1.
  • 15. orb@nostacktrace.com Infinite application λs.(s s) λs.(s s) ! λs.(s s) λs.(s s) ! λs.(s s) λs.(s s) ! … the halting problem Norman Richards Just as you’d expect, there’s no algorithm to determine whether or not a given lambda expression will terminate
  • 16. orb@nostacktrace.com Turing Complete I: λx.x K: λx.λy.x S: λx.λy.λz.x z (y z) Norman Richards http://en.wikipedia.org/wiki/SKI_combinator_calculus
  • 17. orb@nostacktrace.com Actually, just two lambdas S K K UNICORN ! λx.λy.λz.(x z (y z)) K K UNICORN ! λy.λz.(K z (y z)) K UNICORN ! λz.(K z (K z)) UNICORN ! K UNICORN (K UNICORN) ! λx.λy.x UNICORN (K UNICORN) ! λy.UNICORN (K UNICORN) Norman Richards ! UNICORN Thus, S K K is computationally equivalent to identity
  • 18. orb@nostacktrace.com Other Turing Complete things Magic: the Gathering http://www.toothycat.net/ ~hologram/Turing/ C++ Templates The number 110 http://citeseerx.ist.psu.edu/ Norman Richards viewdoc/summary? http://mathworld.wolfram.com/ doi=10.1.1.14.3670 Rule110.html
  • 19. orb@nostacktrace.com TURING TARPIT Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy. Alan Perlis Norman Richards http://pu.inf.uni-tuebingen.de/users/klaeren/epigrams.html
  • 20. orb@nostacktrace.com Currying function(x) { return function(y) { return function (z) { A function that returns a FUNCTION return UNICORN; .. that returns a function that returns a function. You can think of this as a function of three arguments. } λx.λy.λz.UNICORN X Y Z } }(X)(Y)(Z); Norman Richards function(x,y,z) { return UNICORN; }(X,Y,Z);
  • 21. orb@nostacktrace.com Currying Sometimes abbreviated Sometimes, you’ll see lambda expressions written like this for clarity. The arguments are still curried. λx y z.UNICORN X Y Z HASKELL CURRY ! λy z.UNICORN Y Z Curry studied combinatory logic, a variant of lambda calculus. ! λz.UNICORN Z ! UNICORN Norman Richards http://www.haskell.org/haskellwiki/Haskell_Brooks_Curry
  • 22. orb@nostacktrace.com data structures CHURCH PAIR ENCODING PAIR takes two arguments, x and y and returns a function that takes another function and applies x and y to it. PAIR: λx.λy.λf.(f x y) BuILDING UP STATE PAIR takes two arguments, x and y and returns a function that takes another function and applies x and y to it. Norman Richards
  • 23. orb@nostacktrace.com data structures PAIR: λx.λy.λf.(f x y) FIRST: λx.λy.x SECOND: λx.λy.y ACCESSOR FUNCTIONS FIRST and SECOND are functions that can be Norman Richards passed to pair. They take two arguments and return the first and second, respectively.
  • 24. orb@nostacktrace.com data structures PAIR: λx.λy.λf.(f x y) DOGCAT: PAIR DOG CAT ! λx.λy.λf.(f x y) DOG CAT ! λy.λf.(f DOG y) CAT ! λf.(f DOG CAT) Norman Richards
  • 25. orb@nostacktrace.com data structures DOGCAT: λf.(f DOG CAT) FIRST: λx.λy.x SECOND: λx.λy.y DOGCAT FIRST ! λf.(f DOG CAT) λx.λy.x ! λx.λy.x DOG CAT Norman Richards ! λy.DOG CAT ! DOG
  • 26. orb@nostacktrace.com data structures DOGCAT: λf.(f DOG CAT) FIRST: λx.λy.x SECOND: λx.λy.y DOGCAT SECOND ! λf.(f DOG CAT) λx.λy.x ! λx.λy.x DOG CAT Norman Richards ! λy.y CAT ! CAT
  • 27. orb@nostacktrace.com data structures RGB: λr.λg.λb.λf.(f r g b) RED: λr.λg.λb.r GREEN: λr.λg.λb.g BLUE: λr.λg.λb.b BLACK_COLOR: RGB 255 255 255 Norman Richards WHITE_COLOR: RGB 0 0 0 NuMBERS? We haven’t seen how to construct numbers yet, but for the moment imagine that we did.
  • 28. orb@nostacktrace.com data structures AVERAGE? AVG: λx.λy.??? If we did have numbers, we could probably do math like simple averaging MIX_RGB: λc1.λc2.λf. (f (AVG (c1 RED) (c2 RED)) (AVG (c1 GREEN)(c2 GREEN)) (AVG (c1 BLUE) (c2 BLUE))) Norman Richards OO LAMBDA? MIX_RGB takes two colors and returns a new color that is the mix of the two
  • 29. orb@nostacktrace.com CONDITIONALS COND: λe1.λe2.λc.(c e1 e2) TRUE: λx.λy.x FALSE: λx.λy.y Look familiar? Think of a boolean condition as a PAIR of values. TRUE selects the first one and FALSE selects the second one. Norman Richards
  • 30. orb@nostacktrace.com CONDITIONALS COND DEAD ALIVE QUBIT ! λe1.λe2.λc.(c e1 e2) DEAD ALIVE QUBIT ! QUBIT DEAD ALIVE ! TRUE DEAD ALIVE ! FALSE DEAD ALIVE ! λx.λy.x DEAD ALIVE ! λx.λy.y DEAD ALIVE Norman Richards ! DEAD ! ALIVE https://www.coursera.org/course/qcomp
  • 31. orb@nostacktrace.com BOOLEAN LOGIC NOT: λx.(COND FALSE TRUE x) AND: λx.λy.(COND y FALSE x) OR: λx.λy.(COND TRUE y x) Norman Richards
  • 32. orb@nostacktrace.com NUMBERS ZERO: λx.x SUCC: λn.λs.(s false n) ONE: SUCC ZERO ! λs.(s false ZERO) TWO: SUCC ONE ! λs.(s false ONE) ! λs.(s false λs.(s false ZERO)) Norman Richards PEANO NUMBERS PEANO numbers are based on a zero function and a successor function
  • 33. orb@nostacktrace.com NUMBERS ISZERO ZERO ZERO: λx.x ! λn.(n FIRST) λx.x ISZERO: λn.(n FIRST) ! λx.x FIRST ! FIRST Norman Richards ! TRUE
  • 34. orb@nostacktrace.com NUMBERS ISZERO: λn.(n FIRST) ONE: λs.(s FALSE ZERO) ISZERO ONE ! λn.(n FIRST) λs.(s FALSE ZERO) ! λs.(s FALSE ZERO) FIRST ! (FIRST FALSE ZERO) Norman Richards ! FALSE
  • 35. orb@nostacktrace.com NUMBERS PRED: λn.(n SECOND) PRED (SUCC NUM) ! λn.(n SECOND) λs.(s FALSE NUM) ! λs.(s FALSE ZERO) SECOND ! SECOND FALSE NUM ! NUM Norman Richards but... ZERO isn’t SUCC of a number
  • 36. orb@nostacktrace.com NUMBERS PRED: λn.(ISZERO n) ZERO (n SECOND) What is Pred of zero? We can at least test for zero and return another number. Norman Richards
  • 37. orb@nostacktrace.com NUMBERS ADD:λx.λy.(ISZERO Y) function add(x,y) { x if (y==0) { (ADD (SUCC X) return x (PRED Y)) } else { return add(x+1,y-1) NOT VALID Recursive definitions aren’t possible . } Norman Richards Remember, names are just syntactics sugar. All definitions must be finite. How do we do this? }
  • 38. orb@nostacktrace.com RECURSION DIVERSION If we could pass the function in Now we’ll make a function of three arguments, the first being the function to recurse on ADD 1:λf.λx.λy.(ISZERO Y) x (f f (SUCC X) (PRED Y)) Then we could call it RECURSIVELY Just remember that the function takes three Norman Richards arguments, so we should pass the function to itself.
  • 39. orb@nostacktrace.com RECURSION DIVERSION ADD 1:λf.λx.λy.(ISZERO Y) x (f f (SUCC X) (PRED Y)) ADD: ADD 1 ADD 1 ! λx.λy.(ISZERO Y) x Norman Richards (ADD 1 ADD1 (SUCC X) (PRED Y)) FINITE DEFINiTION This definition of ADD is a bit repetitive, but it doesn’t recurse infinitely. If only we could clean this up a bit...
  • 40. orb@nostacktrace.com BEHOLD, the Y combinator Y: λf.(λs.(f (s s)) (λs.(f (s s))) ADD 1: λf.λx.λy.(ISZERO Y) X (F (SUCC X) (PRED Y)) ADD: Y ADD 1 ! λs.(ADD 1 (s s)) (λs.(ADD1 (s s)) ! ADD1 (λs.(ADD1 (s s)) λs.(ADD1 (s s))) Norman Richards ! ADD1 (Y ADD1) ! ADD1 ADD Y self replicates This is similar to the hand prior call, except that the replication state is in the passed function.
  • 41. orb@nostacktrace.com CHURCH NUMBERs ZERO: λf.λx.x ONE: λf.λx.f x TWO: λf.λx.f (f x) THREE: λf.λx.f (f (f x)) FOUR: λf.λx.f (f (f (f x))) repeated function application Norman Richards Church numbers take a function and an argument and apply the function to the argument n times. So N is defined by doing something N times.
  • 42. orb@nostacktrace.com CHURCH NUMBERs ZERO: λn.(n λx.FALSE TRUE) SUCC: λn.λf.λx.f (n f x) ADD: λm.λn.λf.λx.m f (n f x) MUL: λm.λn.λf.m (n f) POW: λm.λn.m n PRED: λn.λf.λx.n (λg.λh. h (g f)) λu.x λu.u Norman Richards No recursion for simple math Church numbers have some very simple operations, Operations like subtraction are more complex than Peano numbers.
  • 43. orb@nostacktrace.com And the rest is functional An introduction to Functional Programming Through Lambda Calculus Greg Michaelson Norman Richards http://www.amazon.com/dp/0486478831
  • 44. orb@nostacktrace.com Leisure https://github.com/zot/Leisure •Lambda Calculus engine written in Javascript •Intended for programming •REPL environment with node.js •Runs in the browser Norman Richards http://tinyconcepts.com/invaders.html
  • 45. orb@nostacktrace.com λ thank you Norman Richards http://www.slideshare.net/normanrichards/the-lambda-calculus-and-the-javascript