Created
June 27, 2021 19:59
-
-
Save tonivade/87a68e1fbb8225b7b23ab1a10c84efd7 to your computer and use it in GitHub Desktop.
Compilation error with type inference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It fails in java 11 to java 16