Skip to content

Instantly share code, notes, and snippets.

@tonivade
Created June 27, 2021 19:59
Show Gist options
  • Save tonivade/87a68e1fbb8225b7b23ab1a10c84efd7 to your computer and use it in GitHub Desktop.
Save tonivade/87a68e1fbb8225b7b23ab1a10c84efd7 to your computer and use it in GitHub Desktop.
Compilation error with type inference
import java.util.function.BiFunction;
import java.util.function.Function;
public interface Bug<T> {
<R> Bug<R> map(Function<? super T, ? extends R> mapper);
<R> Bug<R> ap(Bug<Function<? super T, ? extends R>> apply);
static <A, B, C> Function<BiFunction<A, B, C>, Bug<C>> compile(Bug<? extends A> fa, Bug<? extends B> fb) {
return apply -> fb.ap(fa.map(curried(apply)));
}
static <A, B, C> Function<BiFunction<A, B, C>, Bug<C>> doesNotCompile(Bug<? extends A> fa, Bug<? extends B> fb) {
return apply -> {
var map = fa.map(curried(apply));
return fb.ap(map); // <-- compilation error
};
}
static <A, B, C> Function<A, Function<B, C>> curried(BiFunction<? super A, ? super B, ? extends C> f) {
return a -> b -> f.apply(a, b);
}
}
@tonivade
Copy link
Author

tonivade commented Jul 1, 2021

also with java 17 EA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment