Docsity

Lambda Calculus: Syntax, Values, Operational Semantics, and Functions, Study notes of Computer Science

Partial preview of the text

Download Lambda Calculus: Syntax, Values, Operational Semantics, and Functions and more Study notes Computer Science in PDF only on Docsity!

CIS 500

Software Foundations

Fall 2002

25 September

CIS 500, 25 September 1

The Pure Lambda Calculus

CIS 500, 25 September 2

Values

v

values:

 x .t

abstraction value

CIS 500, 25 September 4

Operational Semantics

Computation rule:

 x .t 12 (^) ) v 2 ! [x 7 ! v 2 (^) ]t 12

(E-A

(^) PP

A

(^) BS

[x 7 ! v 2 (^) ] t 12

is “the term that results from substituting occurrences

of

x

in

t 12

with

v 2

CIS 500, 25 September 5

T

erminology

A term of the form

 x.t) v

— that is, a



-abstraction applied to a

value — is called a redex (from “reducible expression”).

CIS 500, 25 September 6

Alternative evaluation strategies

Some other common ones:standard conventions found in most mainstream languages.The evaluation strategy we have chosen — called call by value — reflects



Full beta-reduction



Normal order (leftmost/outermost)



Call by name (cf. Haskell)

CIS 500, 25 September 7

Multiple arguments

On Monday, we wrote a function

double

that returns a function as an

argument.

double

 f.  y. f (f y)

This idiom — a



-abstraction that does nothing but immediately yield

another abstraction — is very common in the



-calculus.

In general,

 x.  y. t

is a function that, given a value

v

for

x

, yields a

function that, given a value

u

for

y

, yields

t

with

v

in place of

x

and

u

in

place of

y

That is,

 x.  y. t

is a two-argument function.

CIS 500, 25 September 9

Aside: Currying

whenever possible.It is considered good style in OCaml to define functions in curried stylereturning another one-argument function is called currying.language like OCaml that provides pairs) to a one-argument functionThe transformation from a function taking a pair of arguments (in a

CIS 500, 25 September 10

The “Church Booleans”

tru

 t.  f. t fls =  t.  f. f tru v w = (  t.  f.t) v w

by definition

! (  f. v) w

reducing the underlined redex

! v

reducing the underlined redex

fls v w = (  t.  f.f) v w

by definition

! (  f. f) w

reducing the underlined redex

! w

reducing the underlined redex

CIS 500, 25 September 12

Functions on Booleans

not

 b. b fls tru

That is,

not

is a function that, given a boolean value

v

, returns

fls

if

v

is

tru

and

tru

if

v

is

fls

CIS 500, 25 September 13

Pairs

pair

 f.  s.  b. b f s fst =  p. p tru snd =  p. p fls

That is,

pair v w

is a function that, when applied to a boolean value

b

applies

b

to

v

and

w

By the definition of booleans, this application yields

v

if

b

is

tru

and

w

if

b

is

fls

, so the first and second projection functions

fst

and

snd

can be

implemented simply by supplying the appropriate boolean.

CIS 500, 25 September 15

Example

fst (pair v w) = fst ((  f.  s.  b. b f s) v w)

by definition

! fst ((  s.  b. b v s) w)

reducing the underlined redex

! fst (  b. b v w)

reducing the underlined redex

= (  p. p tru) (  b. b v w)

by definition

! (  b. b v w) tru

reducing the underlined redex

! tru v w

reducing the underlined redex

!  v

as before.

CIS 500, 25 September 16

Functions on Church Numerals

Successor:

CIS 500, 25 September 18

Functions on Church Numerals

Successor:

scc

 n.  s.  z. s (n s z) CIS 500, 25 September 18-a