Recursion and Fixed-Point Theory: Programming Language Principles
Recursion and Fixed-Point Theory: Programming Language Principles
Prepared by
Consider Factorial:
let rec f n = n eq 0 1 | n*f(n-1) in f 3 Without the 'rec', we'd have ( f.f 3) [ n.n eq 0 1 | n*f(n-1) ] Note: the last 'f' is free. The 'rec' makes the last 'f' bound to the [ n. ...] expression.
(abstraction). Now there are no free occurrences of f in F, and only one free occurrence of f overall.
=>
=>, 3*2*1*1
Note:
Normal order is required. In PL order the evaluation would not terminate. Lemma: YF is in fact the factorial function. Proof (by induction, see notes).
Prepared by