It's perfectly well typed in System F as "forall a. (a -> a) -> a".
(Haskell)
anyType :: a
anyType = anyType
or(Rust)
fn any_type<T>() -> T {
any_type()
}Extensions with a letrec-like construct are common, and are sometimes inaccurately called 'System F', but those languages do not have the properties of System F.
Could you use your Java code to define Factorial?
private static interface FuncToTFunc<T> {
Func<T> apply(FuncToTFunc<T> x);
}
BTW, what is "x" in the above?Also is Func defined mutually recursively with FuncToFunc in excerpt below?
public static <T> Func<T> Y(final Func<Func<T>> r) {
return ((FuncToTFunc<T>) f -> f.apply(f))
.apply(
f -> r.apply(
x -> f.apply(f).apply(x)));
}FuncToFunc are defined recursively.
Interface Func doesn't refer to FuncToFunc in its declaration, and interface FuncToFunc doesn't refer to Func. The method Y does refer to those two interfaces, but it's declared later than those are, and they don't (and can't, acvtually) refer to it.