Plt1213 5

(C) Ralf Lämmel, Andrei Varanovich, University of Koblenz Landau

Logistics

Assignment

Prolog implementations of relevant lambda calculi are available here:

Another applied lambda calculus

The existing implementation of an applied lambda calculus essentially goes through some modularity trickery to extend NB into a lambda calculus with NB-like support for numbers and Booleans. Have a look at don't get lost in these levels of modular composition. Use it for inspiration, if you like.

Start from the code of the untyped lambda calculus and patch it to add Booleans (with and, or, negation) directly and Prolog numbers (with +,-,*,/) as well as comparison for numbers (==,<,>,<=,>=). Thus, numbers and comparisons are treated differently than in NB. Try to factor code well so that you don't have too much code cloning in the eval predicate for all these many operations. (Again, you don't have to use the same crazy, modular approach as mentioned above.)

Demonstrate your result with a demonstration of the factorial function. You will need to use a fixed point combinator. This one should do it:

lam(f,app(
            lam(x,app(var(f),lam(y,app(app(var(x),var(x)),var(y))))),
            lam(x,app(var(f),lam(y,app(app(var(x),var(x)),var(y)))))))

Prolog variables as lambda variables

Warning: you are entering the hacking corner of this course. If you handle this one, then you deserve a "hero badge" for this course, at least, the Prolog part thereof. Also, you will understand substitution in ways that make your life more meaningful.

The existing implementation of the lambda calculus uses Prolog atoms for the representation of lambda variables. Arguably, one might want to take advantage that Prolog readily implements substitution by representing lambda variables instead as Prolog variables. Revise the implementation accordingly. You will be able to kick out the implementation of substitution.

Important hint: you are quite likely to need a weapon like this to get the semantics of beta reduction operationally right: copy_term/2