CS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus

Size: px
Start display at page:

Download "CS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus"

Transcription

1 CS 4110 Programming Languages & Logics Lecture 17 Programming in the λ-calculus 10 October 2014

2 Announcements 2 Foster Office Hours Enjoy fall break!

3 Review: Church Booleans 3 We can encode TRUE, FALSE, and IF, as follows: TRUE λx. λy. x FALSE λx. λy. y IF λb. λt. λf. b t f

4 Review: Church Booleans 3 We can encode TRUE, FALSE, and IF, as follows: TRUE λx. λy. x FALSE λx. λy. y IF λb. λt. λf. b t f It is easy to see that and IF TRUE v v v IF FALSE v v v

5 Church Numerals 4 Church numerals encode a number n as a function that takes f and x, and applies f to x n times. 0 λf. λx. x 1 λf. λx. f x 2 λf. λx. f (f x)

6 Church Numerals 4 Church numerals encode a number n as a function that takes f and x, and applies f to x n times. 0 λf. λx. x 1 λf. λx. f x 2 λf. λx. f (f x) We can define other functions on integers: SUCC λn. λf. λx. f (n f x)

7 Church Numerals 4 Church numerals encode a number n as a function that takes f and x, and applies f to x n times. 0 λf. λx. x 1 λf. λx. f x 2 λf. λx. f (f x) We can define other functions on integers: SUCC λn. λf. λx. f (n f x) PLUS λn 1. λn 2. n 1 SUCC n 2 TIMES λn 1. λn 2. n 1 PLUS n 2 ZERO

8 Church Numerals 4 Church numerals encode a number n as a function that takes f and x, and applies f to x n times. 0 λf. λx. x 1 λf. λx. f x 2 λf. λx. f (f x) We can define other functions on integers: SUCC λn. λf. λx. f (n f x) PLUS λn 1. λn 2. n 1 SUCC n 2 TIMES λn 1. λn 2. n 1 PLUS n 2 ZERO ISZERO λn. n (λz. false) true

9 Recursive Functions 5 How would we write recursive functions like factorial?

10 Recursive Functions 5 How would we write recursive functions like factorial? We d like to write it like this... FACT λn. IF (ISZERO n) 1 (TIMES n (FACT (PRED n)))

11 Recursive Functions 5 How would we write recursive functions like factorial? We d like to write it like this... FACT λn. IF (ISZERO n) 1 (TIMES n (FACT (PRED n))) In slightly more readable notation this is... FACT λn. if n = 0 then 1 else n FACT (n 1)...but this is an equation, not a definition!

12 Recursion removal trick 6 We can perform a trick to define a function FACT that satisfies the recursive equation on the preveous slide.

13 Recursion removal trick 6 We can perform a trick to define a function FACT that satisfies the recursive equation on the preveous slide. Define a new function FACT : FACT λf. λn. if n = 0 then 1 else n (f f (n 1))

14 Recursion removal trick 6 We can perform a trick to define a function FACT that satisfies the recursive equation on the preveous slide. Define a new function FACT : FACT λf. λn. if n = 0 then 1 else n (f f (n 1)) Then define FACT as FACT applied to itself: FACT FACT FACT

15 Example 7 Let s try evaluating FACT on 3...

16 Example 7 Let s try evaluating FACT on 3... FACT 3

17 Example 7 Let s try evaluating FACT on 3... FACT 3 = (FACT FACT ) 3

18 Example 7 Let s try evaluating FACT on 3... FACT 3 = (FACT FACT ) 3 = ((λf. λn. if n = 0 then 1 else n (f f (n 1))) FACT ) 3

19 Example 7 Let s try evaluating FACT on 3... FACT 3 = (FACT FACT ) 3 = ((λf. λn. if n = 0 then 1 else n (f f (n 1))) FACT ) 3 (λn. if n = 0 then 1 else n (FACT FACT (n 1))) 3

20 Example 7 Let s try evaluating FACT on 3... FACT 3 = (FACT FACT ) 3 = ((λf. λn. if n = 0 then 1 else n (f f (n 1))) FACT ) 3 (λn. if n = 0 then 1 else n (FACT FACT (n 1))) 3 if 3 = 0 then 1 else 3 (FACT FACT (3 1))

21 Example 7 Let s try evaluating FACT on 3... FACT 3 = (FACT FACT ) 3 = ((λf. λn. if n = 0 then 1 else n (f f (n 1))) FACT ) 3 (λn. if n = 0 then 1 else n (FACT FACT (n 1))) 3 if 3 = 0 then 1 else 3 (FACT FACT (3 1)) 3 (FACT FACT (3 1))

22 Example 7 Let s try evaluating FACT on 3... FACT 3 = (FACT FACT ) 3 = ((λf. λn. if n = 0 then 1 else n (f f (n 1))) FACT ) 3 (λn. if n = 0 then 1 else n (FACT FACT (n 1))) 3 if 3 = 0 then 1 else 3 (FACT FACT (3 1)) 3 (FACT FACT (3 1))...

23 Example 7 Let s try evaluating FACT on 3... FACT 3 = (FACT FACT ) 3 = ((λf. λn. if n = 0 then 1 else n (f f (n 1))) FACT ) 3 (λn. if n = 0 then 1 else n (FACT FACT (n 1))) 3 if 3 = 0 then 1 else 3 (FACT FACT (3 1)) 3 (FACT FACT (3 1))

24 Example 7 Let s try evaluating FACT on 3... FACT 3 = (FACT FACT ) 3 = ((λf. λn. if n = 0 then 1 else n (f f (n 1))) FACT ) 3 (λn. if n = 0 then 1 else n (FACT FACT (n 1))) 3 if 3 = 0 then 1 else 3 (FACT FACT (3 1)) 3 (FACT FACT (3 1))

25 Example 7 Let s try evaluating FACT on 3... FACT 3 = (FACT FACT ) 3 = ((λf. λn. if n = 0 then 1 else n (f f (n 1))) FACT ) 3 (λn. if n = 0 then 1 else n (FACT FACT (n 1))) 3 if 3 = 0 then 1 else 3 (FACT FACT (3 1)) 3 (FACT FACT (3 1)) So we have a technique for writing recursive functions: write a function f that takes itself as an argument and define f as f f.

26 Fixpoint combinators 8 There is another way of writing recursive functions... we can express the recursive function as the fixed point of some other, higher-order function, and then take its fixed point.

27 Fixpoint combinators 8 There is another way of writing recursive functions... we can express the recursive function as the fixed point of some other, higher-order function, and then take its fixed point. Consider factorial again. It is a fixed point of the following: G λf. λn. if n = 0 then 1 else n (f (n 1)) Recall that if g if a fixed point of G, then we have G g = g.

28 Fixpoint combinators 8 There is another way of writing recursive functions... we can express the recursive function as the fixed point of some other, higher-order function, and then take its fixed point. Consider factorial again. It is a fixed point of the following: G λf. λn. if n = 0 then 1 else n (f (n 1)) Recall that if g if a fixed point of G, then we have G g = g. There are a number of fixed point combinators, such as the Y combinator. Thus, we can define the factorial function FACT to be simply Y G, the fixed point of G.

29 Y Combinator 9 The (infamous) Y combinator is defined as Y λf. (λx. f (x x)) (λx. f (x x)).

30 Y Combinator 9 The (infamous) Y combinator is defined as Y λf. (λx. f (x x)) (λx. f (x x)). It was discovered by Haskell Curry, and is one of the simplest fixed-point combinators.

31 Y Combinator 9 The (infamous) Y combinator is defined as Y λf. (λx. f (x x)) (λx. f (x x)). It was discovered by Haskell Curry, and is one of the simplest fixed-point combinators. Note how similar its defnition is to omega: omega (λx. x x) (λx. x x)

32 Z Combinator 10 What happens when we evaluate Y G under CBV?

33 Z Combinator 10 What happens when we evaluate Y G under CBV? To avoid this issue, we ll use a slight variant of the Y combinator, Z, which is easier to use under CBV.

34 Z Combinator 10 What happens when we evaluate Y G under CBV? To avoid this issue, we ll use a slight variant of the Y combinator, Z, which is easier to use under CBV. Z λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))

35 Example 11 Let s see Z in action, on our function G

36 Example 11 Let s see Z in action, on our function G FACT

37 Example 11 Let s see Z in action, on our function G FACT = Z G

38 Example 11 Let s see Z in action, on our function G FACT = Z G = (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) G

39 Example 11 Let s see Z in action, on our function G FACT = Z G = (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) G (λx. G (λy. x x y)) (λx. G (λy. x x y))

40 Example 11 Let s see Z in action, on our function G FACT = Z G = (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) G (λx. G (λy. x x y)) (λx. G (λy. x x y)) G (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y)

41 Example 11 Let s see Z in action, on our function G FACT = Z G = (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) G (λx. G (λy. x x y)) (λx. G (λy. x x y)) G (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) = (λf. λn. if n = 0 then 1 else n (f (n 1)))

42 Example 11 Let s see Z in action, on our function G FACT = Z G = (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) G (λx. G (λy. x x y)) (λx. G (λy. x x y)) G (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) = (λf. λn. if n = 0 then 1 else n (f (n 1))) (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y)

43 Example 11 Let s see Z in action, on our function G FACT = Z G = (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) G (λx. G (λy. x x y)) (λx. G (λy. x x y)) G (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) = (λf. λn. if n = 0 then 1 else n (f (n 1))) (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) λn. if n = 0 then 1

44 Example 11 Let s see Z in action, on our function G FACT = Z G = (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) G (λx. G (λy. x x y)) (λx. G (λy. x x y)) G (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) = (λf. λn. if n = 0 then 1 else n (f (n 1))) (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) λn. if n = 0 then 1 else n ((λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) (n 1))

45 Example 11 Let s see Z in action, on our function G FACT = Z G = (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) G (λx. G (λy. x x y)) (λx. G (λy. x x y)) G (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) = (λf. λn. if n = 0 then 1 else n (f (n 1))) (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) λn. if n = 0 then 1 else n ((λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) (n 1)) = β λn. if n = 0 then 1 else n (λy. (Z G) y) (n 1)

46 Example 11 Let s see Z in action, on our function G FACT = Z G = (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) G (λx. G (λy. x x y)) (λx. G (λy. x x y)) G (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) = (λf. λn. if n = 0 then 1 else n (f (n 1))) (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) λn. if n = 0 then 1 else n ((λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) (n 1)) = β λn. if n = 0 then 1 else n (λy. (Z G) y) (n 1) = β λn. if n = 0 then 1 else n (Z G (n 1))

47 Example 11 Let s see Z in action, on our function G FACT = Z G = (λf. (λx. f (λy. x x y)) (λx. f (λy. x x y))) G (λx. G (λy. x x y)) (λx. G (λy. x x y)) G (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) = (λf. λn. if n = 0 then 1 else n (f (n 1))) (λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) λn. if n = 0 then 1 else n ((λy. (λx. G (λy. x x y)) (λx. G (λy. x x y)) y) (n 1)) = β λn. if n = 0 then 1 else n (λy. (Z G) y) (n 1) = β λn. if n = 0 then 1 else n (Z G (n 1)) = λn. if n = 0 then 1 else n (FACT (n 1))

48 Other fixpoint combinators 12 There are many (indeed infinitely many) fixed-point combinators. Here s a cute one: where Y k (L L L L L L L L L L L L L L L L L L L L L L L L L L) L λabcdefghijklmnopqstuvwxyzr. (r (t h i s i s a f i x e d p o i n t c o m b i n a t o r))

49 Turing s Fixpoint Combinator 13 To gain some more intuition for fixpoint combinators, let s derive a combinator Θ originally discovered by Turing.

50 Turing s Fixpoint Combinator 13 To gain some more intuition for fixpoint combinators, let s derive a combinator Θ originally discovered by Turing. Suppose we have a higher order function f, and want the fixed point of f.

51 Turing s Fixpoint Combinator 13 To gain some more intuition for fixpoint combinators, let s derive a combinator Θ originally discovered by Turing. Suppose we have a higher order function f, and want the fixed point of f. We know that Θ f is a fixed point of f, so we have Θ f = f (Θ f).

52 Turing s Fixpoint Combinator 13 To gain some more intuition for fixpoint combinators, let s derive a combinator Θ originally discovered by Turing. Suppose we have a higher order function f, and want the fixed point of f. We know that Θ f is a fixed point of f, so we have Θ f = f (Θ f). This means, that we can write the following recursive equation: Θ = λf. f (Θ f).

53 Turing s Fixpoint Combinator To gain some more intuition for fixpoint combinators, let s derive a combinator Θ originally discovered by Turing. Suppose we have a higher order function f, and want the fixed point of f. We know that Θ f is a fixed point of f, so we have Θ f = f (Θ f). This means, that we can write the following recursive equation: Θ = λf. f (Θ f). Now use the recursion removal trick: Θ λt. λf. f (t t f) Θ Θ Θ 13

54 Example 14 FACT = Θ G

55 Example 14 FACT = Θ G = ((λt. λf. f (t t f)) (λt. λf. f (t t f))) G

56 Example 14 FACT = Θ G = ((λt. λf. f (t t f)) (λt. λf. f (t t f))) G (λf. f ((λt. λf. f (t t f)) (λt. λf. f (t t f)) f)) G

57 Example 14 FACT = Θ G = ((λt. λf. f (t t f)) (λt. λf. f (t t f))) G (λf. f ((λt. λf. f (t t f)) (λt. λf. f (t t f)) f)) G G ((λt. λf. f (t t f)) (λt. λf. f (t t f)) G)

58 Example 14 FACT = Θ G = ((λt. λf. f (t t f)) (λt. λf. f (t t f))) G (λf. f ((λt. λf. f (t t f)) (λt. λf. f (t t f)) f)) G G ((λt. λf. f (t t f)) (λt. λf. f (t t f)) G) = G (Θ G)

59 Example 14 FACT = Θ G = ((λt. λf. f (t t f)) (λt. λf. f (t t f))) G (λf. f ((λt. λf. f (t t f)) (λt. λf. f (t t f)) f)) G G ((λt. λf. f (t t f)) (λt. λf. f (t t f)) G) = G (Θ G) = (λf. λn. if n = 0 then 1 else n (f (n 1))) (Θ G)

60 Example 14 FACT = Θ G = ((λt. λf. f (t t f)) (λt. λf. f (t t f))) G (λf. f ((λt. λf. f (t t f)) (λt. λf. f (t t f)) f)) G G ((λt. λf. f (t t f)) (λt. λf. f (t t f)) G) = G (Θ G) = (λf. λn. if n = 0 then 1 else n (f (n 1))) (Θ G) λn. if n = 0 then 1 else n ((Θ G) (n 1))

61 Example 14 FACT = Θ G = ((λt. λf. f (t t f)) (λt. λf. f (t t f))) G (λf. f ((λt. λf. f (t t f)) (λt. λf. f (t t f)) f)) G G ((λt. λf. f (t t f)) (λt. λf. f (t t f)) G) = G (Θ G) = (λf. λn. if n = 0 then 1 else n (f (n 1))) (Θ G) λn. if n = 0 then 1 else n ((Θ G) (n 1)) = λn. if n = 0 then 1 else n (FACT (n 1))

62 Definitional Translation 15 We have seen how to encode a number of high-level language constructs booleans, conditionals, natural numbers, and recursion in λ-calculus.

63 Definitional Translation 15 We have seen how to encode a number of high-level language constructs booleans, conditionals, natural numbers, and recursion in λ-calculus. In definitional translation, where we define the meaning of language constructs by translation to another language.

64 Definitional Translation 15 We have seen how to encode a number of high-level language constructs booleans, conditionals, natural numbers, and recursion in λ-calculus. In definitional translation, where we define the meaning of language constructs by translation to another language. This is a form of denotational semantics, but instead of the target being mathematical objects, it is a simpler programming language (such as λ-calculus).

65 Definitional Translation 15 We have seen how to encode a number of high-level language constructs booleans, conditionals, natural numbers, and recursion in λ-calculus. In definitional translation, where we define the meaning of language constructs by translation to another language. This is a form of denotational semantics, but instead of the target being mathematical objects, it is a simpler programming language (such as λ-calculus). For each language construct, we define an operational semantics directly, and then give an alternate semantics by translation to a simpler language.

66 Review: Call-by-Value Recall the syntax and CBV semantics of λ-calculus: e ::= x λx. e e 1 e 2 v ::= λx. e e 1 e 1 e e e 1 e 2 e 1 e 2 v e v e (λx. e) v e{v/x} β Note that there are two kinds of rules: congruence rules that specify evaluation order and computation rules that specify the interesting reductions. 16

67 Evaluation Contexts 17 Evaluation contexts are a simple mechanism that separates out these two kinds of rules.

68 Evaluation Contexts 17 Evaluation contexts are a simple mechanism that separates out these two kinds of rules. An evaluation context E (sometimes written E[ ]) is an expression with a hole in it, that is with a single occurrence of the special symbol [ ] (called the hole ) in place of a subexpression.

69 Evaluation Contexts 17 Evaluation contexts are a simple mechanism that separates out these two kinds of rules. An evaluation context E (sometimes written E[ ]) is an expression with a hole in it, that is with a single occurrence of the special symbol [ ] (called the hole ) in place of a subexpression. Evaluation contexts are defined using a BNF grammar that is similar to the grammar used to define the language. E ::= [ ] E e v E

70 Evaluation Contexts 17 Evaluation contexts are a simple mechanism that separates out these two kinds of rules. An evaluation context E (sometimes written E[ ]) is an expression with a hole in it, that is with a single occurrence of the special symbol [ ] (called the hole ) in place of a subexpression. Evaluation contexts are defined using a BNF grammar that is similar to the grammar used to define the language. E ::= [ ] E e v E We write E[e] to mean the evaluation context E where the hole has been replaced with the expression e.

71 Examples 18

72 Examples 18 E 1 = [ ] (λx. x) E 1 [λy. y y] = (λy. y y) λx. x

73 Examples 18 E 1 = [ ] (λx. x) E 1 [λy. y y] = (λy. y y) λx. x E 2 = (λz. z z) [ ] E 2 [λx. λy. x] = (λz. z z) (λx. λy. x)

74 Examples 18 E 1 = [ ] (λx. x) E 1 [λy. y y] = (λy. y y) λx. x E 2 = (λz. z z) [ ] E 2 [λx. λy. x] = (λz. z z) (λx. λy. x) E 3 = ([ ] λx. x x) ((λy. y) (λy. y)) E 3 [λf. λg. f g] = ((λf. λg. f g) λx. x x) ((λy. y) (λy. y))

75 CBV With Evaluation Contexts 19 With evaluation contexts, we can define the evaluation semantics for the pure CBV λ-calculus with just two rules, one for evaluation contexts, and one for β-reduction.

76 CBV With Evaluation Contexts 19 With evaluation contexts, we can define the evaluation semantics for the pure CBV λ-calculus with just two rules, one for evaluation contexts, and one for β-reduction. First we define the contexts: E ::= [ ] E e v E

77 CBV With Evaluation Contexts With evaluation contexts, we can define the evaluation semantics for the pure CBV λ-calculus with just two rules, one for evaluation contexts, and one for β-reduction. First we define the contexts: E ::= [ ] E e v E Then we define the small-step rules: e e E[e] E[e ] (λx. e) v e{v/x} β 19

78 CBN With Evaluation Contexts 20 We can also define the semantics of CBN λ-calculus with evaluation contexts.

79 CBN With Evaluation Contexts 20 We can also define the semantics of CBN λ-calculus with evaluation contexts. First we define the contexts: E ::= [ ] E e

80 CBN With Evaluation Contexts We can also define the semantics of CBN λ-calculus with evaluation contexts. First we define the contexts: E ::= [ ] E e Then we define the small-step rules: e e E[e] E[e ] (λx. e) e e{e /x} β 20

81 Multiple Arguments 21 Our syntax for functions only allows function with a single argument: λx. e.

82 Multiple Arguments 21 Our syntax for functions only allows function with a single argument: λx. e. We can define a language that allows functions to have multiple arguments. e ::= x λx 1,..., x n. e e 0 e 1... e n Here, a function λx 1,..., x n. e takes n arguments, with names x 1 through x n. In a multi argument application e 0 e 1... e n, we expect e 0 to evaluate to an n-argument function, and e 1,..., e n are the arguments that we will give the function.

83 Multiple Arguments We can define a CBV operational semantics for the multi-argument λ-calculus as follows. E ::= [ ] v 0... v i 1 E e i+1... e n e e E[e] E[e ] (λx 1,..., x n. e 0 ) v 1... v n e 0 {v 1 /x 1 }{v 2 /x 2 }... {v n /x n } β Note that the evaluation contexts ensure that we evaluate multi-argument applications e 0 e 1... e n from left to right. 22

84 Definitional Translation 23 The multi-argument λ-calculus isn t any more expressive that the pure λ-calculus.

85 Definitional Translation 23 The multi-argument λ-calculus isn t any more expressive that the pure λ-calculus. We can define a translation T [[ ]] that takes an expression in the multi-argument λ-calculus and returns an equivalent expression in the pure λ-calculus.

86 Definitional Translation 23 The multi-argument λ-calculus isn t any more expressive that the pure λ-calculus. We can define a translation T [[ ]] that takes an expression in the multi-argument λ-calculus and returns an equivalent expression in the pure λ-calculus. T [[x]] = x T [[λx 1,..., x n. e]] = λx λx n. T [[e]] T [[e 0 e 1 e 2... e n ]] = (... ((T [[e 0 ]] T [[e 1 ]]) T [[e 2 ]])... T [[e n ]])

87 Currying 24 This process of rewriting a function that takes multiple arguments as a chain of functions that each take a single argument is called currying.

88 Currying 24 This process of rewriting a function that takes multiple arguments as a chain of functions that each take a single argument is called currying. Consider a mathematical function that takes two arguments, the first from domain A and the second from domain B, and returns a result from domain C.

89 Currying 24 This process of rewriting a function that takes multiple arguments as a chain of functions that each take a single argument is called currying. Consider a mathematical function that takes two arguments, the first from domain A and the second from domain B, and returns a result from domain C. We can describe this function, using mathematical notation for function domains, as an element of A B C.

90 Currying 24 This process of rewriting a function that takes multiple arguments as a chain of functions that each take a single argument is called currying. Consider a mathematical function that takes two arguments, the first from domain A and the second from domain B, and returns a result from domain C. We can describe this function, using mathematical notation for function domains, as an element of A B C. Currying this function produces an element of A (B C).

91 Currying This process of rewriting a function that takes multiple arguments as a chain of functions that each take a single argument is called currying. Consider a mathematical function that takes two arguments, the first from domain A and the second from domain B, and returns a result from domain C. We can describe this function, using mathematical notation for function domains, as an element of A B C. Currying this function produces an element of A (B C). That is, the curried version takes an argument from domain A, and returns a function that takes an argument from domain B and produces a result of domain C. 24

CIS 500 Software Foundations Fall September 25

CIS 500 Software Foundations Fall September 25 CIS 500 Software Foundations Fall 2006 September 25 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial programming language, then the

More information

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Tuesday, February 19, 2013 The lambda calculus (or λ-calculus) was introduced by Alonzo Church and Stephen Cole Kleene in

More information

Type Systems Winter Semester 2006

Type Systems Winter Semester 2006 Type Systems Winter Semester 2006 Week 4 November 8 November 15, 2006 - version 1.1 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial

More information

The Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements

The Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements CIS 500 Software Foundations Fall 2004 27 September IS 500, 27 September 1 The Lambda Calculus IS 500, 27 September 3 Announcements Homework 1 is graded. Pick it up from Cheryl Hickey (Levine 502). We

More information

Chapter 5: The Untyped Lambda Calculus

Chapter 5: The Untyped Lambda Calculus Chapter 5: The Untyped Lambda Calculus What is lambda calculus for? Basics: syntax and operational semantics Programming in the Lambda Calculus Formalities (formal definitions) What is Lambda calculus

More information

Concepts of programming languages

Concepts of programming languages Concepts of programming languages Lecture 5 Wouter Swierstra 1 Announcements Submit your project proposal to me by email on Friday; The presentation schedule in now online Exercise session after the lecture.

More information

Denotational Semantics; Lambda Calculus Basics Section and Practice Problems Week 4: Tue Feb 13 Fri Feb 16, 2018

Denotational Semantics; Lambda Calculus Basics Section and Practice Problems Week 4: Tue Feb 13 Fri Feb 16, 2018 Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Denotational Semantics; Lambda Calculus Basics Week 4: Tue Feb 13 Fri Feb 16, 2018 1 Denotational Semantics (a) Give the

More information

CS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 7 Lambda Calculus Dan Grossman Spring 2011 Where we are Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now:

More information

Programming Languages. Programming with λ-calculus. Lecture 11: Type Systems. Special Hour to discuss HW? if-then-else int

Programming Languages. Programming with λ-calculus. Lecture 11: Type Systems. Special Hour to discuss HW? if-then-else int CSE 230: Winter 2010 Principles of Programming Languages Lecture 11: Type Systems News New HW up soon Special Hour to discuss HW? Ranjit Jhala UC San Diego Programming with λ-calculus Encode: bool if-then-else

More information

Fall 2013 Midterm Exam 10/22/13. This is a closed-book, closed-notes exam. Problem Points Score. Various definitions are provided in the exam.

Fall 2013 Midterm Exam 10/22/13. This is a closed-book, closed-notes exam. Problem Points Score. Various definitions are provided in the exam. Programming Languages Fall 2013 Midterm Exam 10/22/13 Time Limit: 100 Minutes Name (Print): Graduate Center I.D. This is a closed-book, closed-notes exam. Various definitions are provided in the exam.

More information

CSE 505: Concepts of Programming Languages

CSE 505: Concepts of Programming Languages CSE 505: Concepts of Programming Languages Dan Grossman Fall 2003 Lecture 6 Lambda Calculus Dan Grossman CSE505 Fall 2003, Lecture 6 1 Where we are Done: Modeling mutation and local control-flow Proving

More information

Whereweare. CS-XXX: Graduate Programming Languages. Lecture 7 Lambda Calculus. Adding data structures. Data + Code. What about functions

Whereweare. CS-XXX: Graduate Programming Languages. Lecture 7 Lambda Calculus. Adding data structures. Data + Code. What about functions Whereweare CS-XXX: Graduate Programming Languages Lecture 7 Lambda Calculus Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now: Didn t IMP leave

More information

Introduction to Lambda Calculus. Lecture 7 CS /08/09

Introduction to Lambda Calculus. Lecture 7 CS /08/09 Introduction to Lambda Calculus Lecture 7 CS 565 02/08/09 Lambda Calculus So far, we ve explored some simple but non-interesting languages language of arithmetic expressions IMP (arithmetic + while loops)

More information

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland COMP 1130 Lambda Calculus based on slides by Jeff Foster, U Maryland Motivation Commonly-used programming languages are large and complex ANSI C99 standard: 538 pages ANSI C++ standard: 714 pages Java

More information

9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete

9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete Dr A Sahu Dept of Computer Science & Engineering IIT Guwahati Why study? Lambda calculus Syntax Evaluation Relationship to programming languages Church Rosser theorem Completeness of Lambda Calculus: Turing

More information

CIS 500 Software Foundations Midterm I Answer key October 8, 2003

CIS 500 Software Foundations Midterm I Answer key October 8, 2003 CIS 500 Software Foundations Midterm I Answer key October 8, 2003 Inductive Definitions Review: Recall that the function size, which calculates the total number of nodes in the abstract syntax tree of

More information

Introduction to the Lambda Calculus

Introduction to the Lambda Calculus Introduction to the Lambda Calculus Overview: What is Computability? Church s Thesis The Lambda Calculus Scope and lexical address The Church-Rosser Property Recursion References: Daniel P. Friedman et

More information

λ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods

λ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods Course 2D1453, 2006-07 Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Alonzo Church, 1903-1995 Church-Turing thesis First

More information

Introduction to Lambda Calculus. Lecture 5 CS 565 1/24/08

Introduction to Lambda Calculus. Lecture 5 CS 565 1/24/08 Introduction to Lambda Calculus Lecture 5 CS 565 1/24/08 Lambda Calculus So far, we ve explored some simple but non-interesting languages language of arithmetic expressions IMP (arithmetic + while loops)

More information

More Lambda Calculus and Intro to Type Systems

More Lambda Calculus and Intro to Type Systems More Lambda Calculus and Intro to Type Systems Plan Heavy Class Participation Thus, wake up! Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems Overview Static, Dyamic

More information

Lecture #3: Lambda Calculus. Last modified: Sat Mar 25 04:05: CS198: Extra Lecture #3 1

Lecture #3: Lambda Calculus. Last modified: Sat Mar 25 04:05: CS198: Extra Lecture #3 1 Lecture #3: Lambda Calculus Last modified: Sat Mar 25 04:05:39 2017 CS198: Extra Lecture #3 1 Simplifying Python Python is full of features. Most are there to make programming concise and clear. Some are

More information

1 Introduction. 3 Syntax

1 Introduction. 3 Syntax CS 6110 S18 Lecture 19 Typed λ-calculus 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic semantics,

More information

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations Outline FP Foundations, Scheme In Text: Chapter 15 Mathematical foundations Functional programming λ-calculus LISP Scheme 2 Imperative Languages We have been discussing imperative languages C/C++, Java,

More information

Formal Systems and their Applications

Formal Systems and their Applications Formal Systems and their Applications Dave Clarke (Dave.Clarke@cs.kuleuven.be) Acknowledgment: these slides are based in part on slides from Benjamin Pierce and Frank Piessens 1 Course Overview Introduction

More information

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic

More information

Fundamentals and lambda calculus

Fundamentals and lambda calculus Fundamentals and lambda calculus Again: JavaScript functions JavaScript functions are first-class Syntax is a bit ugly/terse when you want to use functions as values; recall block scoping: (function ()

More information

Computer Science 203 Programming Languages Fall Lecture 10. Bindings, Procedures, Functions, Functional Programming, and the Lambda Calculus

Computer Science 203 Programming Languages Fall Lecture 10. Bindings, Procedures, Functions, Functional Programming, and the Lambda Calculus 1 Computer Science 203 Programming Languages Fall 2004 Lecture 10 Bindings, Procedures, Functions, Functional Programming, and the Lambda Calculus Plan Informal discussion of procedures and bindings Introduction

More information

Lambda Calculus. Lecture 4 CS /26/10

Lambda Calculus. Lecture 4 CS /26/10 Lambda Calculus Lecture 4 CS 565 10/26/10 Pure (Untyped) Lambda Calculus The only value is a function Variables denote functions Functions always take functions as arguments Functions always return functions

More information

Untyped Lambda Calculus

Untyped Lambda Calculus Advanced Topics in Programming Languages Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and Programming

More information

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e

More information

The Untyped Lambda Calculus

The Untyped Lambda Calculus CS738: Advanced Compiler Optimizations The Untyped Lambda Calculus Amey Karkare karkare@cse.iitk.ac.in http://www.cse.iitk.ac.in/~karkare/cs738 Department of CSE, IIT Kanpur Reference Book Types and Programming

More information

More Lambda Calculus and Intro to Type Systems

More Lambda Calculus and Intro to Type Systems #1 More Lambda Calculus and Intro to Type Systems #2 Plan Heavy Class Participation Thus, wake up! (not actually kidding) Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems

More information

CSC173 Lambda Calculus Lambda Calculus Evaluation (10 min) Evaluate this expression (β-reduce with normal-order evaluation):

CSC173 Lambda Calculus Lambda Calculus Evaluation (10 min) Evaluate this expression (β-reduce with normal-order evaluation): CSC173 Lambda Calculus 014 Please write your name on the bluebook. You may use two sides of handwritten notes. There are 90 possible points and 75 is a perfect score. Stay cool and please write neatly.

More information

CITS3211 FUNCTIONAL PROGRAMMING. 10. Programming in the pure λ calculus

CITS3211 FUNCTIONAL PROGRAMMING. 10. Programming in the pure λ calculus CITS3211 FUNCTIONAL PROGRAMMING 10. Programming in the pure λ calculus Summary: This lecture demonstates the power of the pure λ calculus by showing that there are λ expressions that can be used to emulate

More information

Untyped Lambda Calculus

Untyped Lambda Calculus Concepts in Programming Languages Recitation 5: Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and

More information

Functions as data. Massimo Merro. 9 November Massimo Merro The Lambda language 1 / 21

Functions as data. Massimo Merro. 9 November Massimo Merro The Lambda language 1 / 21 Functions as data Massimo Merro 9 November 2011 Massimo Merro The Lambda language 1 / 21 The core of sequential programming languages In the mid 1960s, Peter Landin observed that a complex programming

More information

Formal Semantics. Aspects to formalize. Lambda calculus. Approach

Formal Semantics. Aspects to formalize. Lambda calculus. Approach Formal Semantics Aspects to formalize Why formalize? some language features are tricky, e.g. generalizable type variables, nested functions some features have subtle interactions, e.g. polymorphism and

More information

Lambda Calculus. Variables and Functions. cs3723 1

Lambda Calculus. Variables and Functions. cs3723 1 Lambda Calculus Variables and Functions cs3723 1 Lambda Calculus Mathematical system for functions Computation with functions Captures essence of variable binding Function parameters and substitution Can

More information

M. Snyder, George Mason University LAMBDA CALCULUS. (untyped)

M. Snyder, George Mason University LAMBDA CALCULUS. (untyped) 1 LAMBDA CALCULUS (untyped) 2 The Untyped Lambda Calculus (λ) Designed by Alonzo Church (1930s) Turing Complete (Turing was his doctoral student!) Models functions, always as 1-input Definition: terms,

More information

1 Scope, Bound and Free Occurrences, Closed Terms

1 Scope, Bound and Free Occurrences, Closed Terms CS 6110 S18 Lecture 2 The λ-calculus Last time we introduced the λ-calculus, a mathematical system for studying the interaction of functional abstraction and functional application. We discussed the syntax

More information

Functional Languages and Higher-Order Functions

Functional Languages and Higher-Order Functions Functional Languages and Higher-Order Functions Leonidas Fegaras CSE 5317/4305 L12: Higher-Order Functions 1 First-Class Functions Values of some type are first-class if They can be assigned to local variables

More information

CIS 500 Software Foundations Midterm I

CIS 500 Software Foundations Midterm I CIS 500 Software Foundations Midterm I October 11, 2006 Name: Student ID: Email: Status: Section: registered for the course not registered: sitting in to improve a previous grade not registered: just taking

More information

Lecture 5: The Untyped λ-calculus

Lecture 5: The Untyped λ-calculus Lecture 5: The Untyped λ-calculus Syntax and basic examples Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Static Analysis Pratikakis (CSD) Untyped λ-calculus I CS49040,

More information

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

5. Introduction to the Lambda Calculus. Oscar Nierstrasz 5. Introduction to the Lambda Calculus Oscar Nierstrasz Roadmap > What is Computability? Church s Thesis > Lambda Calculus operational semantics > The Church-Rosser Property > Modelling basic programming

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 1 Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Use currying

More information

Pure (Untyped) λ-calculus. Andrey Kruglyak, 2010

Pure (Untyped) λ-calculus. Andrey Kruglyak, 2010 Pure (Untyped) λ-calculus Andrey Kruglyak, 2010 1 Pure (untyped) λ-calculus An example of a simple formal language Invented by Alonzo Church (1936) Used as a core language (a calculus capturing the essential

More information

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals Review CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics e ::= λx. e x ee c v ::= λx. e c (λx. e) v e[v/x] e 1 e 2 e 1 e 2 τ ::= int τ τ Γ ::= Γ,x : τ e 2 e 2 ve 2 ve 2 e[e /x]:

More information

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242 Spring 2013 Foundations Yu Zhang Acknowledgement: modified from Stanford CS242 https://courseware.stanford.edu/pg/courses/317431/ Course web site: http://staff.ustc.edu.cn/~yuzhang/fpl Reading Concepts

More information

Functional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur

Functional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur Functional Programming and λ Calculus Amey Karkare Dept of CSE, IIT Kanpur 0 Software Development Challenges Growing size and complexity of modern computer programs Complicated architectures Massively

More information

One of a number of approaches to a mathematical challenge at the time (1930): Constructibility

One of a number of approaches to a mathematical challenge at the time (1930): Constructibility λ Calculus Church s λ Calculus: Brief History One of a number of approaches to a mathematical challenge at the time (1930): Constructibility (What does it mean for an object, e.g. a natural number, to

More information

INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS. Instructors: Crista Lopes Copyright Instructors.

INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS. Instructors: Crista Lopes Copyright Instructors. INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS Instructors: Crista Lopes Copyright Instructors. History Formal mathematical system Simplest programming language Intended for studying functions, recursion

More information

Exercise 1 ( = 18 points)

Exercise 1 ( = 18 points) 1 Exercise 1 (4 + 5 + 4 + 5 = 18 points) The following data structure represents polymorphic binary trees that contain values only in special Value nodes that have a single successor: data Tree a = Leaf

More information

Lecture Notes on Data Representation

Lecture Notes on Data Representation Lecture Notes on Data Representation 15-814: Types and Programming Languages Frank Pfenning Lecture 9 Tuesday, October 2, 2018 1 Introduction In this lecture we ll see our type system in action. In particular

More information

Exercise 1 ( = 24 points)

Exercise 1 ( = 24 points) 1 Exercise 1 (4 + 5 + 4 + 6 + 5 = 24 points) The following data structure represents polymorphic binary trees that contain values only in special Value nodes that have a single successor: data Tree a =

More information

Lecture 9: More Lambda Calculus / Types

Lecture 9: More Lambda Calculus / Types Lecture 9: More Lambda Calculus / Types CSC 131 Spring, 2019 Kim Bruce Pure Lambda Calculus Terms of pure lambda calculus - M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete

More information

- M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete. - true = λ u. λ v. u. - false = λ u. λ v.

- M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete. - true = λ u. λ v. u. - false = λ u. λ v. Pure Lambda Calculus Lecture 9: More Lambda Calculus / Types CSC 131 Spring, 2019 Kim Bruce Terms of pure lambda calculus - M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete

More information

The Lambda Calculus. notes by Don Blaheta. October 12, A little bondage is always a good thing. sk

The Lambda Calculus. notes by Don Blaheta. October 12, A little bondage is always a good thing. sk The Lambda Calculus notes by Don Blaheta October 2, 2000 A little bondage is always a good thing. sk We ve seen that Scheme is, as languages go, pretty small. There are just a few keywords, and most of

More information

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy 06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 6: Polymorphic Type Systems 1. Polymorphic

More information

Costly software bugs that could have been averted with type checking

Costly software bugs that could have been averted with type checking Type Checking Class Notes from Lectures 6 and 7 Lahav Yeffet and Ori Folger The material in these lectures is based on the textbook Types and Programming Languages by Benjamin Pierce. Here is a list of

More information

Exercise 1 (2+2+2 points)

Exercise 1 (2+2+2 points) 1 Exercise 1 (2+2+2 points) The following data structure represents binary trees only containing values in the inner nodes: data Tree a = Leaf Node (Tree a) a (Tree a) 1 Consider the tree t of integers

More information

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 14 Tuesday, March 24, 2015 1 Parametric polymorphism Polymorph means many forms. Polymorphism is the ability of

More information

CSE-321 Programming Languages 2010 Midterm

CSE-321 Programming Languages 2010 Midterm Name: Hemos ID: CSE-321 Programming Languages 2010 Midterm Score Prob 1 Prob 2 Prob 3 Prob 4 Total Max 15 30 35 20 100 1 1 SML Programming [15 pts] Question 1. [5 pts] Give a tail recursive implementation

More information

CS 6110 S14 Lecture 1 Introduction 24 January 2014

CS 6110 S14 Lecture 1 Introduction 24 January 2014 CS 6110 S14 Lecture 1 Introduction 24 January 2014 1 Introduction What is a program? Is it just something that tells the computer what to do? Yes, but there is much more to it than that. The basic expressions

More information

Lecture 9: Typed Lambda Calculus

Lecture 9: Typed Lambda Calculus Advanced Topics in Programming Languages Spring Semester, 2012 Lecture 9: Typed Lambda Calculus May 8, 2012 Lecturer: Mooly Sagiv Scribe: Guy Golan Gueta and Shachar Itzhaky 1 Defining a Type System for

More information

Programming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.

Programming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine. CMSC 330: Organization of Programming Languages Lambda Calculus Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Ø Use currying or tuples

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 1 Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Ø Use currying

More information

CMPUT 325 : Lambda Calculus Basics. Lambda Calculus. Dr. B. Price and Dr. R. Greiner. 13th October 2004

CMPUT 325 : Lambda Calculus Basics. Lambda Calculus. Dr. B. Price and Dr. R. Greiner. 13th October 2004 CMPUT 325 : Lambda Calculus Basics Dr. B. Price and Dr. R. Greiner 13th October 2004 Dr. B. Price and Dr. R. Greiner CMPUT 325 : Lambda Calculus Basics 1 Lambda Calculus Lambda calculus serves as a formal

More information

Programming Languages

Programming Languages Programming Languages Lambda Calculus and Scheme CSCI-GA.2110-003 Fall 2011 λ-calculus invented by Alonzo Church in 1932 as a model of computation basis for functional languages (e.g., Lisp, Scheme, ML,

More information

Advanced Topics in Programming Languages Lecture 3 - Models of Computation

Advanced Topics in Programming Languages Lecture 3 - Models of Computation Advanced Topics in Programming Languages Lecture 3 - Models of Computation Andrey Leshenko Maxim Borin 16/11/2017 1 Lambda Calculus At the beginning of the last century, several attempts were made to theoretically

More information

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm Gradescope ID: (Gradescope ID is the First letter of your last name and last 5 digits of your UID) (If you write your name on the test, or your gradescope ID

More information

Elixir, functional programming and the Lambda calculus.

Elixir, functional programming and the Lambda calculus. Elixir, functional programming and the Lambda calculus. Programming II - Elixir Version Johan Montelius Spring Term 2018 Introduction In this tutorial you re going to explore lambda calculus and how it

More information

Introduction to the Lambda Calculus. Chris Lomont

Introduction to the Lambda Calculus. Chris Lomont Introduction to the Lambda Calculus Chris Lomont 2010 2011 2012 www.lomont.org Leibniz (1646-1716) Create a universal language in which all possible problems can be stated Find a decision method to solve

More information

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson Lambda Calculus CS 550 Programming Languages Jeremy Johnson 1 Lambda Calculus The semantics of a pure functional programming language can be mathematically described by a substitution process that mimics

More information

CMSC 336: Type Systems for Programming Languages Lecture 4: Programming in the Lambda Calculus Acar & Ahmed 22 January 2008.

CMSC 336: Type Systems for Programming Languages Lecture 4: Programming in the Lambda Calculus Acar & Ahmed 22 January 2008. CMSC 336: Type Systems for Programming Languages Lecture 4: Programming in the Lambda Calculus Acar & Ahmed 22 January 2008 Contents 1 Announcements 1 2 Solution to the Eercise 1 3 Introduction 1 4 Multiple

More information

CS 4110 Programming Languages & Logics. Lecture 28 Recursive Types

CS 4110 Programming Languages & Logics. Lecture 28 Recursive Types CS 4110 Programming Languages & Logics Lecture 28 Recursive Types 7 November 2014 Announcements 2 Foster office hours 11-12pm Guest lecture by Fran on Monday Recursive Types 3 Many languages support recursive

More information

We defined congruence rules that determine the order of evaluation, using the following evaluation

We defined congruence rules that determine the order of evaluation, using the following evaluation CS 4110 Programming Languages and Logics Lectures #21: Advanced Types 1 Overview In this lecture we will extend the simply-typed λ-calculus with several features we saw earlier in the course, including

More information

Recursion. Lecture 6: More Lambda Calculus Programming. Fixed Points. Recursion

Recursion. Lecture 6: More Lambda Calculus Programming. Fixed Points. Recursion Recursion Lecture 6: More Lambda Calculus Programming CSC 131! Fall, 2014!! Kim Bruce Recursive definitions are handy! - fact = λn. cond (iszero n) 1 (Mult n (fact (Pred n)))! - Not a legal definition

More information

Exercise 1 ( = 22 points)

Exercise 1 ( = 22 points) 1 Exercise 1 (4 + 3 + 4 + 5 + 6 = 22 points) The following data structure represents polymorphic lists that can contain values of two types in arbitrary order: data DuoList a b = C a (DuoList a b) D b

More information

Introduction to the λ-calculus

Introduction to the λ-calculus Announcements Prelim #2 issues: o Problem 5 grading guide out shortly o Problem 3 (hashing) issues Will be on final! Friday RDZ office hours are 11-12 not 1:30-2:30 1 Introduction to the λ-calculus Today

More information

Constraint-based Analysis. Harry Xu CS 253/INF 212 Spring 2013

Constraint-based Analysis. Harry Xu CS 253/INF 212 Spring 2013 Constraint-based Analysis Harry Xu CS 253/INF 212 Spring 2013 Acknowledgements Many slides in this file were taken from Prof. Crista Lope s slides on functional programming as well as slides provided by

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC 330 Spring 2017 1 Review A lambda calculus expression is defined as e ::= x variable λx.e abstraction (fun def) e e application

More information

Pure Lambda Calculus. Lecture 17

Pure Lambda Calculus. Lecture 17 Pure Lambda Calculus Lecture 17 Lambda Calculus Lambda Calculus (λ-calculus) is a functional notation introduced by Alonzo Church in the early 1930s to formalize the notion of computability. Pure λ-calculus

More information

Homework. Lecture 7: Parsers & Lambda Calculus. Rewrite Grammar. Problems

Homework. Lecture 7: Parsers & Lambda Calculus. Rewrite Grammar. Problems Homework Lecture 7: Parsers & Lambda Calculus CSC 131 Spring, 2019 Kim Bruce First line: - module Hmwk3 where - Next line should be name as comment - Name of program file should be Hmwk3.hs Problems How

More information

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 18 Thursday, April 3, 2014 1 Error-propagating semantics For the last few weeks, we have been studying type systems.

More information

CMSC 330: Organization of Programming Languages. Lambda Calculus Encodings

CMSC 330: Organization of Programming Languages. Lambda Calculus Encodings CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC330 Spring 2018 1 The Power of Lambdas Despite its simplicity, the lambda calculus is quite expressive: it is Turing complete!

More information

Semantics of programming languages

Semantics of programming languages Semantics of programming languages Informatics 2A: Lecture 27 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 21 November, 2011 1 / 19 1 2 3 4 2 / 19 Semantics for programming

More information

COMP80 Lambda Calculus Programming Languages Slides Courtesy of Prof. Sam Guyer Tufts University Computer Science History Big ideas Examples:

COMP80 Lambda Calculus Programming Languages Slides Courtesy of Prof. Sam Guyer Tufts University Computer Science History Big ideas Examples: COMP80 Programming Languages Slides Courtesy of Prof. Sam Guyer Lambda Calculus Formal system with three parts Notation for functions Proof system for equations Calculation rules called reduction Idea:

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC 330 Summer 2017 1 The Power of Lambdas Despite its simplicity, the lambda calculus is quite expressive: it is Turing complete!

More information

Semantics of programming languages

Semantics of programming languages Semantics of programming languages Informatics 2A: Lecture 28 Mary Cryan School of Informatics University of Edinburgh mcryan@inf.ed.ac.uk 21 November 2018 1 / 18 Two parallel pipelines A large proportion

More information

Graphical Untyped Lambda Calculus Interactive Interpreter

Graphical Untyped Lambda Calculus Interactive Interpreter Graphical Untyped Lambda Calculus Interactive Interpreter (GULCII) Claude Heiland-Allen https://mathr.co.uk mailto:claude@mathr.co.uk Edinburgh, 2017 Outline Lambda calculus encodings How to perform lambda

More information

Last class. CS Principles of Programming Languages. Introduction. Outline

Last class. CS Principles of Programming Languages. Introduction. Outline Last class CS6848 - Principles of Programming Languages Principles of Programming Languages V. Krishna Nandivada IIT Madras Interpreters A Environment B Cells C Closures D Recursive environments E Interpreting

More information

λ calculus is inconsistent

λ calculus is inconsistent Content Rough timeline COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Gerwin Klein, June Andronick, Toby Murray λ Intro & motivation, getting started [1] Foundations & Principles

More information

Introductory Example

Introductory Example CSc 520 Principles of Programming Languages 21: Lambda Calculus Introduction Christian Collberg Department of Computer Science University of Arizona collberg@cs.arizona.edu Copyright c 2005 Christian Collberg

More information

CSE-321 Programming Languages 2012 Midterm

CSE-321 Programming Languages 2012 Midterm Name: Hemos ID: CSE-321 Programming Languages 2012 Midterm Prob 1 Prob 2 Prob 3 Prob 4 Prob 5 Prob 6 Total Score Max 14 15 29 20 7 15 100 There are six problems on 24 pages in this exam. The maximum score

More information

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER 2012 2013 MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS Time allowed TWO hours Candidates may complete the front

More information

Harvard School of Engineering and Applied Sciences Computer Science 152

Harvard School of Engineering and Applied Sciences Computer Science 152 Harvard School of Engineering and Applied Sciences Computer Science 152 Lecture 17 Tuesday, March 30, 2010 1 Polymorph means many forms. Polymorphism is the ability of code to be used on values of different

More information

To figure this out we need a more precise understanding of how ML works

To figure this out we need a more precise understanding of how ML works Announcements: What are the following numbers: 74/2/70/17 (2:30,2:30,3:35,7:30) PS2 due Thursday 9/20 11:59PM Guest lecture on Tuesday 9/25 o No RDZ office hours next Friday, I am on travel A brief comment

More information

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu, Lambda Calculus Type Systems, Lectures 3 Jevgeni Kabanov Tartu, 13.02.2006 PREVIOUSLY ON TYPE SYSTEMS Arithmetical expressions and Booleans Evaluation semantics Normal forms & Values Getting stuck Safety

More information

λ-calculus Lecture 1 Venanzio Capretta MGS Nottingham

λ-calculus Lecture 1 Venanzio Capretta MGS Nottingham λ-calculus Lecture 1 Venanzio Capretta MGS 2018 - Nottingham Table of contents 1. History of λ-calculus 2. Definition of λ-calculus 3. Data Structures 1 History of λ-calculus Hilbert s Program David Hilbert

More information

CS 314 Principles of Programming Languages. Lecture 21

CS 314 Principles of Programming Languages. Lecture 21 CS 314 Principles of Programming Languages Lecture 21 Zheng Zhang Department of Computer Science Rutgers University Wednesday 23 rd November, 2016 Zheng Zhang 1 CS@Rutgers University Class Information

More information