%l
Proof: take W = %l x.F ( xx ) and X = WW, then X = WW = ( \%l x.F ( xx ) ) W = F ( WW ) = FX slide: The lambda calculus -- properties
%l_{ <= }
int S(int x) { return x+1; } int twice(int f(int), int y) { return f(f(y)); } int twice_S(int y) { return twice(S,y); } slide: Types in C++
int SD(double x) { return x+1; } // twice(SD) rejected slide: SD example
%l_{ /\ }
C++
void f(int, double); void f(double, int); f(1,2.0); // f(int, double); f(2.0,1); // f(double,int); f(1,1); // error: ambiguous slide: example
class P; class C; void f(P* p) { cout << "f(P*)"; } // (1) void f(C* c) { cout << "f(C*)"; } // (2) class P { public: virtual void f() { cout << "P::f"; }// (3) }; class C : public P { public: virtual void f() { cout << "C::f"; } // (4) }; slide: Static versus dynamic selection
P* p = new P; // static and dynamic P* C* c = new C; // static and dynamic C* P* pc = new C; // static P*, dynamic C* f(p); // f(P*) f(c); // f(C*) f(pc); // f(P*) p->f(); // P::f c->f(); // C::f pc->f(); // C::f
F_{ <= }
Point* move(Point* p, int d); // require int Point::x Point* move(Point* p, int d) { p.x += d; return p; } slide: example move
template< class T > // requires T::value() class P { public: P(T& r) : t(r) {} int operator==( P& p) { return t.value() == p.t.value(); } private: T& t; }; slide: Type abstraction in C++
template< class T > class A { A<T> public: virtual T value() = 0; }; class Int : public A<int> { // Int <= A<int> public: Int(int n = 0) : _n(n) {} int value() { return _n; } private: int _n; }; slide: Type instantiation
Int i1, i2; P<Int> p1(i1), p2(i2); if ( p1 == p2 ) cout << "OK" << endl; OK slide: Example P