









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of fixed points in functional programming, focusing on recursion and the use of fixed-point combinators. It discusses the fixed-point semantics of objects and the typed and polymorphic lambda calculus. References are provided for further study.
Typology: Papers
1 / 17
This page cannot be seen from the preview
Don't miss anything!










Com S 541
Overview:^!^
Recursion and the fixed-point combinator! Fixed-point semantics of objects! The typed lambda-calculus! The polymorpic lambda calculus References:^!^
H.P. Barendregt, “The Lambda Calculus – Its Syntax and Semantics”, North-Holland, 1984! David A. Schmidt, “Denotational Semantics – A Methodology for LanguageDevelopment”, Allyn and Bacon Inc., 1986! Joseph E. Stoy, “Denotational Semantics – The Scott-Strachey Approach toProgramming Language Theory”, MIT Press, 1992! William R. Cook, “A Denotational Semantics of Inheritance”, Ph.D., BrownUniversity, 1989
Com S 541
!^ Suppose we want to define arithmetic operations on our lambda-encodednumbers (see “Representing Numbers”).In Haskell we can program:
plus n m
| n == 0 = m| otherwise = plus (n-1) (m+1) so we might try to define:plus
≡ λ^ n m. iszero n m (plus (pred n) (succ m)) !^ Unfortunately this is not a definition, since we are trying to use “plus” beforeit is defined. Although recursion is fundamental to functional programming, itis not primitive in the lambda calculus, so we must find a way to “program” it!
Com S 541
!^ In gener
al,a fixed poi
ntofa f
unction i
s a value i
n the funct
ion’s dom ai
n,
w hich i
s m apped t
o itselfby t
he funct
ion.Ther
efore,a
fixed point of a
function
fis a value
p^ such that
f p = p
!^ Examples:
fact 1 = 1fact 2 = 2fib 0 = 0fib 1 = 1 λx. 27 = 27 λx. 6 – x = 3 !^ However, not all functions have exactly one fixed point: “succ n = n + 1”has none, while “id” has infinitely many.
Com S 541
Fixed point Theorem:^ For every
F^ there exists a fixed point
X^ such that
Proof:^ Let
Y^ ≡ λf. (
λx. f (x x)) (
λx. f (x x))
Now consider:X^
(λx. F (x x)) (
λx. F (x x)) "^ F ((λ
x. F (x x)) (
λx. F (x x)))
"^ F X Therefore, the “Y combinator” can always be used to find a fixed point ofan arbitrary lambda expression, if such a fixed point exists.
Com S 541
!^ We cannot write:
plus^ ≡ λ
n m. iszero n m (plus (pred n) (succ m)) because plus is unbound in the “definition”.! We can, however, abstract over plus:rplus
≡ λ^ plus n m. iszero n m (plus (pred n) (succ m)) !^ Now we seek a lambda expression plus, such that:
rplus plus
↔^ plus !^ I. e., plus is a fixed point of rplus. By the fixed point theorem, we can take:
plus^ ≡^
Y rplus
Com S 541
= (Y rplus) 1 1^ "
rplus plus 1 1 " iszero 1 1 (plus (pred 1) (succ 1)) " False 1 (plus (pred 1) (succ 1)) " plus (pred 1) (succ 1) " rplus plus (pred 1) (succ 1) " iszero (pred 1) (succ 1) (plus (pred (pred 1)) (succ (succ 1))) " iszero 0 (succ 1) (...) " True (succ 1) (...) " succ 1 " 2
Com S 541
!^ Fixed-point semantics of recursive programs provides the mathematicalsetting for an inheritance model for an object-oriented language.!^ Consider the following definition of the factorial function:
λn.^ if^
n = 1^ then
^1 else
The identifier fact is equated with a function definition, in which “fact”appears. Thus the definition is self-referential. The use of the name fact torepresent the self-reference is however just a syntactic convention. Inobject-oriented languages we commonly use the special symbol
self :
λn.^ if^
n = 1^ then
^1 else
n * self (n – 1)
Com S 541
!^ By using fixed-point technique, recursive definitions can by transformedinto a non-recursive form:
λself.
λn.^ if
n = 1^
then^^1
else^ n * self (n – 1)
But now
Such value is called a “fixed point” of
possible to compute a unique fixed point, the least fixed point, of anyfunction by using the fixed-point function “fix” that has the followingproperty: if
f= fix(
F), then
F(f)= f
Com S 541
Definition:A function intended to specify a fixed point whose formal parameterrepresents self-reference is called generator. Thus a generator has theform
G =^ λ^ self. body
where self may occur free in body. Intuitively, self-reference is “unbound”in a generator, while self-reference in its fixed point is connected back tothe generator.
client
O Fixed point
O Generator
self
Com S 541
Com S 541
Definition:A wrapper is a function designed to modify a self-referential structure in aself-referential way; it has two parameters, one representing self-referenceand the other representing the superstructure being modified. Thus awrapper is a function of the form
W =^ λ^
self.^ λ
super. Body
where self and super may occur free in body.! The application of a wrapper to a generator involves binding together self-reference in the wrapper and the generator, and then applying thewrapper modification to the value of the generator:W
λ^ self. W(self)(G(self)), where
⊕^ =^ λ
a.^ λb.^
λs. a(s)(b(s))
Com S 541
client^
W^
G super self
self