Lambda Calculus Prof. Tom Austin San Jos State University Minimum - - PowerPoint PPT Presentation

lambda calculus
SMART_READER_LITE
LIVE PREVIEW

Lambda Calculus Prof. Tom Austin San Jos State University Minimum - - PowerPoint PPT Presentation

CS 252: Advanced Programming Language Principles Lambda Calculus Prof. Tom Austin San Jos State University Minimum complete programming language? WARNING: I expect you to remember every construct of this language for exams Lambda


slide-1
SLIDE 1

CS 252: Advanced Programming Language Principles

  • Prof. Tom Austin

San José State University

Lambda Calculus

slide-2
SLIDE 2

Minimum complete programming language?

slide-3
SLIDE 3

WARNING: I expect you to remember every construct of this language for exams

slide-4
SLIDE 4

Lambda Calculus expressions

e ::= x | (λx.e) | e e expressions: variables lambda abstractions function application

We could have just said "function", but we want to sound cool

slide-5
SLIDE 5

Lambda Calculus values

v ::= (λx.e) values: lambda abstractions

When our program finishes running, it returns some complex function as its "value"

slide-6
SLIDE 6

Function application

Suppose we have a function: (λx.E) Where E is some complex expression. How do we evaluate: (λx.E) v à E[x->v]

v replaces x wherever it

  • ccurs in E
slide-7
SLIDE 7

Small step semantics for λ-calculus

(in-class)

slide-8
SLIDE 8

Operational Semantics e1 -> e1' e1 e2 -> e1' e2 (λx.e) v -> e[x->v] e2 -> e2' (λx.e) e2 -> (λx.e) e2'

[Ctxt1] [Ctxt2] [Call]

slide-9
SLIDE 9

Example: Identity Function

(λx.x) (λa.λb.a) à x[x->(λa.λb.a)] à (λa.λb.a)

slide-10
SLIDE 10

When should we evaluate function arguments?

slide-11
SLIDE 11

Strict Evaluation Strategies

Evaluate function arguments first

  • Call-by-value:

copy of the parameter is passed

  • Call-by-reference:

implicit reference is passed

slide-12
SLIDE 12

Lazy Evaluation Strategies

Substitute arguments in function body

  • Call-by-name:

re-evaluate the argument each time

  • Call-by-need:

memoizes parameter value after use

slide-13
SLIDE 13

How powerful is this language?

slide-14
SLIDE 14

The lambda-calculus is Turing complete. You can also implement the λ-calculus w/ a Turing machine

In other words, the two are equal in power

slide-15
SLIDE 15

Translating λ-calc to Haskell

x (λx.e) e e x (\x -> e) e e

Lambda-calculus Haskell

slide-16
SLIDE 16

Extending the lambda calculus

(in class)

slide-17
SLIDE 17

Lab: Develop new features in the Lambda Calculus using Haskell

Details on Canvas. Starter code is available on the course website.