If it helps, the equivalent Java signature is:
interface Sum<A, B> { <T> T visit(Function<A, T> onA, Function<B, T> onB); }