1 / 35

CSE-321 Programming Languages  -Calculus (II)

CSE-321 Programming Languages  -Calculus (II). 박성우. POSTECH March 26, 2007. :  -reduction. redex = reducible expression. Values and Reductions. Call-by-name Call-by-value. Outline. Abstract syntax of the  -calculus V Operational semantics of the l -calculus V Substitutions

rod
Download Presentation

CSE-321 Programming Languages  -Calculus (II)

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. CSE-321 Programming Languages-Calculus (II) 박성우 POSTECH March 26, 2007

  2. : -reduction redex = reducible expression Values and Reductions

  3. Call-by-name Call-by-value

  4. Outline • Abstract syntax of the -calculus V • Operational semantics of the l-calculus V • Substitutions • Programming in the -calculus

  5. [e' / x] e • Informally"substitute e' for every occurrence of x in e." • Examples

  6. Easy Cases First

  7. Two Remaining Cases

  8. First (stupid) attempt • Second attempt • But wait:

  9. Bound Variables • Names of bound variables do not matter. • Hence • for a fresh variable y,

  10. One Remaining Case

  11. A Naive Attempt • An anomaly: something for y

  12. Free Variables • Variables that are bound nowhere FV(e) = set of free variables in e

  13. ? Free Variables Remain Free • From the point of view of an outside observer,a free variable remains free until it is explicitly replaced. variable capture outside observer

  14. Capture-Avoiding Substitution • What happens if • the free variable y is captured and becomes a bound variable. • To an outside observer, it suddenly disappears!

  15. Substitution Completed

  16. Capture-Avoiding Substitution in Action • We have to rename bound variables as necessary.

  17. -Conversion • Renaming bound variables when necessary • Okay because the names of bound variables do not matter. • Examples

  18. Formalization of -Conversion • See the course notes! • It's more interesting than you might think.

  19. Outline • Abstract syntax of the -calculus V • Operational semantics of the l-calculus V • Substitutions V • Programming in the -calculus

  20. Booleans • A boolean value • "Give me two options and I will choose one for you!" • Syntactic sugar

  21. Examples • Under the call-by-name strategy,

  22. Logical Operators

  23. Natural Numbers • A natural number n • has the capability to repeat a given process n times. • "Give me a function f and I will return f n = f o f ... f o f "

  24. Church Numerals

  25. Addition • Key observation:

  26. Multiplication • Key observation: • Alternatively

  27. Recursive Functions in -Calculus • Plan of attack • Assume a recursive function constructfun f x. e • Rewrite it as an expression in the -calculusi.e., show that it is syntactic sugar.

  28. Example: Factorial • Plan of attack • Assume a recursive function construct • Rewrite it as an expression in the -calculusi.e., show that it is syntactic sugar.

  29. fac to FAC

  30. FAC produces a new function from f

  31. Now we only need to find a fixed point of:

  32. Fixed Point • Fixed point of function f V such that V = f (V) • Ex. f (x) = 2 - x fixed point of f = 11 = f (1)

  33. Magic Revealed • Fixed point combinator / Y combinator (call-by-value) • fix F returns a fixed point of F.

  34. Now we only need to find a fixed point of: Now we only need to compute:

  35. Answer

More Related