Programming Techniques.

The functional language is quite powerful enough to perform any computation. This section gives examples; they are principally numerical but only because such examples are easily stated and have short solutions.
let rec fact = lambda n. if n=0 then 1 else n*fact(n-1)
in fact 10

{\fB Factorial. \fP}

The factorial function can also be evaluated using the paradoxical operator Y as described in an earlier section.

let Y = lambda G. (lambda g. G(g g)) (lambda g. G(g g))

in let F = lambda f. lambda n. if n=0 then 1 else n*f(n-1)

in Y F 10

{\fB Factorial via Y \fP}

[Previous Page] [Next Page] [Index] © L. Allison, Dept. of Computer Science, Monash University