CSC 530 Lecture Notes Week 3
A Brief Review of Lambda Calculus
Introduction to Programming Language Type Systems
Lambda Calculus
Notation |
Lisp
Notation |
λ x.x | (lambda (x) x) |
f = λ x.x |
(defun f (x) x)
-- or -- (setq f (lambda (x) x)) |
f 1 |
(f 1)
-- or -- (apply f (list 1)) |
g = λ x.f x | (defun g (x) (f x)) |
which delivers 11.(apply (lambda (x) (+ x 1)) '(10))
versus(defun f (x) (+ x 1))
that is, f and g define the same function.(setq g (lambda (x) (+ x 1)))
(setq memory (lambda (x) (cadr (assoc x '( (x 10) (y 20) (z 30))))))
(apply memory '(y))
(excuse the nconc, please).(defun add-binding (memory binding) (nconc (cadadr (cdadar (nthcdr 5 memory))) (list binding)))
forall type T, function Eq(x:T, y:T) = x = y;
class A = ... ; class B subclass of A = ... ; class C subclass of a = ... ; function Eq(x:A, y:A) = x = y;
(deftype name type) where type is * one of the atomic type names sym, int, real, string, or bool * a composite type specified with one or more of the four type forms below * the name of a defined type, including a recursive reference to such a name * a type variable of the form ?X, for any atom X (array type [bounds]) where bounds is either an integer, or (integer integer) pair, or a type var (record fields) where fields is a list of (name type) pairs in which all names must be unique; fields may be a single type var (union fields) where fields is a list of (name type) pairs in which all names and types must be unique; fields may be a single type var (function args outs [suchthat]) where args and outs are lists of names or (name type) pairs; names and (name type) pairs can be mixed in a signature; the name in a (name type) pair may be empty; args and/or outs may each be a single type var; suchthat is of the form (suchthat predicate), and the predicate can reference type vars
(defun name args [outs] [suchthat] body) where args, outs, and suchthat are as defined above for the function type
Type | Literal Denotation |
sym | any quoted atom |
int | any atom for which integerp is true |
real | any atom for which numberp is true and integerp is false |
string | any atom for which stringp is true |
bool | t or nil |
array | a list, the elements of which meet the array's bounds and type specs |
array | a list, the elements of which meet the record's field specs |
union | a value whose type is one of field types |
function | the name of a defun'd function or a lambda expression whose signature matches the function type's args and outs specs |