markdown
Basics of Binding and Free Variablesmd 283170c
lecture/information/programming-languages/foundation/variable-binding-and-free-variables-basics.lecture.n.md
Download PDF

Basics of Binding and Free Variables

1Introduction

This lecture defines the syntax of lambda terms and classifies every variable occurrence as bound or free. A name alone does not determine the classification; the occurrence's position and the scope of its binder are essential.

2Syntax and syntax trees

Let [PARSE ERROR: Undefined("Command(\"mathcal\")")]V be a countably infinite set of variables. The set Λ of untyped lambda terms is defined recursively by the grammar

M::=x(MN)(λx.M)(x[PARSE ERROR: Undefined("Command(\"mathcal\")")]V).

Here x is a variable, MN is an application, and λx.M is an abstraction. When parentheses are omitted, application associates to the left and the body of an abstraction extends as far to the right as possible. Thus MNP=(MN)P and λx.MN=λx.(MN).

3Binders, scopes, and occurrences

In λx.M, the prefix λx is a binder for x, and the subterm M is its scope. An occurrence of x at a leaf of the syntax tree is bound if it lies inside the body of some λx. If several such binders enclose the occurrence, the nearest one in the syntax tree binds it. An occurrence of x that lies in the scope of no λx is free.

Boundness is a property of an occurrence, not merely of a variable name. For example, in

x(λx.x),

the leftmost occurrence of x is free, whereas the rightmost occurrence is bound by the inner λx. In

λx.((λx.x)x),

the occurrence in the inner body is bound by the inner binder, while the final occurrence is bound by the outer binder. This phenomenon is called shadowing.

4The set of free variables

FV(M) is the set of variable names that have at least one free occurrence in M. It is defined structurally by

FV(x)={x},
FV(MN)=FV(M)FV(N),
FV(λx.M)=FV(M){x}.

For example,

FV(λx.xy)={y},FV(λx.λy.xy)=[PARSE ERROR: Undefined("Command(\"varnothing\")")].

A term M is closed if FV(M)=[PARSE ERROR: Undefined("Command(\"varnothing\")")] and open otherwise. A term is closed exactly when every variable occurrence is bound by some binder.

5Check

In M=λx.(x(λy.xy)z), both occurrences of x are bound by the outer λx, the occurrence of y is bound by λy, and only the occurrence of z is free. Hence FV(M)={z}. The next lecture uses this occurrence-level classification to define substitution that avoids capture.

6Related links

data/lecture/information/programming-languages/foundation/introduction-to-functional-programming.lecture.n.md data/lecture/information/programming-languages/foundation/substitution-and-alpha-equivalence-basics.lecture.n.md
raw .n.md をコピー
loc をコピー (filepath:line ~ line)
copy share link
copy encoded share link
path をコピー
copy share link
copy encoded share link
copy share link
copy encoded share link
タブを全て閉じる