CICE ambiguity
rzwitserloot posted in programming on November 25th, 2006
Wherein I post a question where the CICE-ification would be unclear. CICE proponents - how should this situation be handled?
Mapping in java:
public interface MapFunction<R, T> {
R function(T in);
}
public class Collections {
public static <R, T> Collection<R> map(
Collection<T> list, MapFunction<R, T> f) {
List<R> retvals = new LinkedList<R>;
for ( T t : list ) retvals.add(f.function(t));
return retvals;
}
}
Now, given the above, let’s say I want to run Math.sin on a bunch of numbers:
Collection<Double> list = Arrays.asList(1.0, 2.0, 3.0, 4.0, 5.0);
Collection<Double> results = Collections.map(list, MapFunction(Double in) {
return Math.sin(in);
});
The problem with the above fragment: Will the inference engine realize that the ‘R’ generics parameter of MapFunction should in this case bind to ‘Double’ as that’s the only thing we ever return here?
Should the inference engine do this automatically? (I don’t think it should)
Will it infer from the fact that we’re assigning to a Collections<Double>? Should the inference do this automatically? (Here, yes, I think so).
As a total aside, having map for java is fun, and CICE makes it relatively painless.

Leave a Response