Y combinator using lambda and method references
aruld at acm.org
Sat Oct 27 14:20:03 PDT 2012
I attempted to port this Y combinator  using Java 8 lambdas. The closest
I can make it work is shown here .
It looks like intellij code inspection suggests I can still reduce this
further by using 2 method references and 1 lambda as shown visually here
, but I run into problems with those conversions.
# 1 Applying the first inspection (line # 19) to a method reference fails
in a compile error:
error: cannot find symbol variable f
#2 Applying the second inspection (line # 22) to a method reference
compiles just fine, but runs into a StackOverflowError. May be this is a
problem with the code itself.
#3 Applying the third inspection (line # 31) to a lambda fails in a compile
error: method Y in class YFact cannot be applied to given types;
found: (final Fun[...] - 1)
reason: cyclic inference - cannot infer target type for given lambda/method
where T is a type-variable:
T extends Object declared in method <T>Y(Func<Func<T>>)
I am not sure if this is a case where the editor is incorrect in detecting
compilation errors. I believe the editor should reject these if the
compiler cannot infer the target type.
Please apologize if this does not belong here.
More information about the lambda-dev