Java funktional?

Motto: a good programmer can write LISP in any language,

hier: LISP = Haskell,

$ ghci
Prelude> let  square x = x*x  
Prelude> map ( succ . square ) [1,2,3]
[2,5,10]

und any = Java:

interface Function<From,To> {
  To apply (From arg);
}
public static void main(String[] args) {
  List<Integer> xs = 
    Arrays.asList(new Integer[] { 1, 2, 3 });
  System.out.println(xs);
  List<Integer> ys = 
    Functions.map(
       Functions.combine(square,succ), xs);
  System.out.println(ys);
}
Schreiben Sie die fehlenden Deklarationen (succ, square, map, combine). Hinweis:
static final Function<Integer, Integer> succ = 
  new Function<Integer, Integer>() {
    public Integer apply(Integer x) {
      return x + 1;
    }
  };
Welcher Bytecode wird erzeugt für
static Function<Integer, Integer> 
  multiplyBy (final Integer y) {
    return new Function<Integer,Integer>() {
      public Integer apply (Integer x) {
        return x*y;
      }
    };
}



Johannes Waldmann 2006-02-02