1 / 27

the lambda calculus

the lambda calculus. David Walker CS 441. the lambda calculus. Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 Church says: “There may, indeed, be other applications of the system than its use as a logic.” Dave says: “I’ll say”. Reading.

etoile
Télécharger la présentation

the lambda calculus

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. the lambda calculus David Walker CS 441

  2. the lambda calculus • Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 • Church says: “There may, indeed, be other applications of the system than its use as a logic.” • Dave says: “I’ll say”

  3. Reading • Pierce, Chapter 5

  4. functions • essentially every full-scale programming language has some notion of function • the (pure) lambda calculus is a language composed entirely of functions • we use the lambda calculus to study the essence of computation • it is just as fundamental as Turing Machines

  5. syntax e ::= x (a variable) | \x.e (a function; in ML: fn x => e) | e e (function application) [ “\” will be written “” in a nice font]

  6. syntax • the identity function: • \x.x • 2 notational conventions: • applications associate to the left (like in ML): • “y z x” is “(y z) x” • the body of a lambda extends as far as possible to the right: • “\x.x \z.x z x” is “\x.(x \z.(x z x))”

  7. terminology • \x.e • \x.x y the scope of x is the term e y is free in the term \x.x y x is bound in the term \x.x y

  8. CBV operational semantics • single-step, call-by-value OS: e --> e’ • values are v ::= \x.e • primary rule (beta reduction): • e [v/x] is the term in which all free occurrences of x in t are replaced with v • this replacement operation is called substitution • we will define it carefully later in the lecture (\x.e) v --> e [v/x]

  9. operational semantics • search rules: • notice, evaluation is left to right e1 --> e1’ e1 e2 --> e1’ e2 e2 --> e2’ v e2 --> v e2’

  10. Example (\x. x x) (\y. y)

  11. Example (\x. x x) (\y. y) --> x x [\y. y / x]

  12. Example (\x. x x) (\y. y) --> x x [\y. y / x] == (\y. y) (\y. y)

  13. Example (\x. x x) (\y. y) --> x x [\y. y / x] == (\y. y) (\y. y) --> y [\y. y / y]

  14. Example (\x. x x) (\y. y) --> x x [\y. y / x] == (\y. y) (\y. y) --> y [\y. y / y] == \y. y

  15. Another example (\x. x x) (\x. x x)

  16. Another example (\x. x x) (\x. x x) --> x x [\x. x x/x]

  17. Another example (\x. x x) (\x. x x) --> x x [\x. x x/x] == (\x. x x) (\x. x x) • In other words, it is simple to write non terminating computations in the lambda calculus • what else can we do?

  18. We can do everything • The lambda calculus can be used as an “assembly language” • We can show how to compile useful, high-level operations and language features into the lambda calculus • Result = adding high-level operations is convenient for programmers, but not a computational necessity • Result = make your compiler intermediate language simpler

  19. Let Expressions • It is useful to bind intermediate results of computations to variables: let x = e1 in e2 • Question: can we implement this idea in the lambda calculus? source = lambda calculus + let translate/compile target = lambda calculus

  20. Let Expressions • It is useful to bind intermediate results of computations to variables: let x = e1 in e2 • Question: can we implement this idea in the lambda calculus? translate (let x = e1 in e2) = (\x.e2) e1

  21. Let Expressions • It is useful to bind intermediate results of computations to variables: let x = e1 in e2 • Question: can we implement this idea in the lambda calculus? translate (let x = e1 in e2) = (\x. translate e2) (translate e1)

  22. Let Expressions • It is useful to bind intermediate results of computations to variables: let x = e1 in e2 • Question: can we implement this idea in the lambda calculus? translate (let x = e1 in e2) = (\x. translate e2) (translate e1) translate (x) = x translate (\x.e) = \x.translate e translate (e1 e2) = (translate e1) (translate e2)

  23. booleans • we can encode booleans • we will represent “true” and “false” as functions named “tru” and “fls” • how do we define these functions? • think about how “true” and “false” can be used • they can be used by a testing function: • “test b then else” returns “then” if b is true and returns “else” if b is false • the only thing the implementation of test is going to be able to do with b is to apply it • the functions “tru” and “fls” must distinguish themselves when they are applied

  24. booleans • the encoding: tru = \t.\f. t fls = \t.\f. f test = \x.\then.\else. x then else

  25. booleans tru = \t.\f. t fls = \t.\f. f test = \x.\then.\else. x then else eg: test tru a b -->* (\t.\f. t) a b -->* a

  26. booleans tru = \t.\f. t fls = \t.\f. f and = \b.\c. b c fls and tru tru -->* tru tru fls -->* tru

  27. booleans tru = \t.\f. t fls = \t.\f. f and = \b.\c. b c fls and fls tru -->* fls tru fls -->* fls

More Related