[PRL] the "success" of types

William D Clinger will at ccs.neu.edu
Sat May 20 16:37:18 EDT 2006


Matthias wrote:
> 5. GC also leaped from FP to OOP in Java.

You mean Smalltalk.  The OO folk then wasted 20 years
by pretending OOP could be practical without GC.

> I will maintain that w/o functional programming
> we wouldn't have seen the progress in types research that influenced
> the last 10 years.

Now *that* is something on which we can agree.

John Clements wrote:
> That is, to the best of my knowledge I can't write an invariant that
> states:
>
> Right now, x and y are both lists of some type T (though at other
> times they might not be of the same type).
>
> ... whereas I _can_ write
>
> This procedure accepts two lists that must both contain the same type T.

import java.util.*;

public class Foo {

    public static int counterexample (List x, List y) {
        List<Integer> xint = (List<Integer>) x;
        List<Integer> yint = (List<Integer>) y;
        return (xint.size() + yint.size())
            * (xint.get(0).intValue() + yint.get(0).intValue());
    }

    public static void main (String[] args) {
        List x = new ArrayList();
        List y = new ArrayList();
        x.add(11);
        y.add(12);
        System.out.println (counterexample (x, y));
    }
}

****************************************************************

% javac Foo.java
Note: Foo.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
% java Foo
46

Will



More information about the PRL mailing list