News for hackers. Stuff that matters.
Re:The Y Combinator by Joker_vD on Tuesday June 29, 2021 @10:48AM (#27676578)
It's perfectly well typed in System F as "forall a. (a -> a) -> a".
Re:The Y Combinator by bidirectional on Tuesday June 29, 2021 @11:28AM (#27677257)
Can you type that in System F? It doesn't seem logically valid, a -> a is trivially true, but apparently implies any a?
Re:The Y Combinator by scapp on Tuesday June 29, 2021 @01:25PM (#27678993)
System F isn't consistent as a logic (pretty much precisely because it has general recursion). In languages with general recursion, you can do things like

(Haskell)

    anyType :: a
    anyType = anyType
or

(Rust)

    fn any_type<T>() -> T {
        any_type()
    }
Re:The Y Combinator by gsg on Wednesday June 30, 2021 @12:23AM (#27684839)
System F doesn't have general recursion.

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.

Re:The Y Combinator by scapp on Wednesday June 30, 2021 @07:00AM (#27687105)
You're right. I must have been thinking of one of those extensions you're talking about (F# maybe?). I should have remembered that System F is part of the lambda cube, so it's at least as consistent as CoC
Re:The Y Combinator by ProfHewitt on Tuesday June 29, 2021 @11:28AM (#27677253)
Could you write this in Java?
Re:The Y Combinator by jhallenworld on Tuesday June 29, 2021 @03:17PM (#27680443)
Here is Y-combinator in many languages:

https://rosettacode.org/wiki/Y_combinator

Re:The Y Combinator by Joker_vD on Tuesday June 29, 2021 @11:42AM (#27677500)
Re:The Y Combinator by ProfHewitt on Tuesday June 29, 2021 @12:24PM (#27678133)
Does the github Java code make use of recursion?
Re:The Y Combinator by Joker_vD on Tuesday June 29, 2021 @02:31PM (#27679852)
As you can clearly see, it does not. It also doesn't use any forced typecasts to circumvent type checking.
Re:The Y Combinator by ProfHewitt on Tuesday June 29, 2021 @03:38PM (#27680744)
Is FuncToFunc defined recursively in the excerpt below???

      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)));
      }
Re:The Y Combinator by ProfHewitt on Wednesday June 30, 2021 @08:30AM (#27687656)
Joker_vD: Looks like you are incorrect because Func and

FuncToFunc are defined recursively.

Re:The Y Combinator by Joker_vD on Monday July 05, 2021 @06:42AM (#27736466)
No, they are not. Do you know what "interface" is in Java, and what is "class"? And what is "method"?

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.

Re:The Y Combinator by bidirectional on Tuesday June 29, 2021 @11:29AM (#27677282)
I think it is approximately `public <T> T y(Function <T, T> f)`.
Re:The Y Combinator by ProfHewitt on Tuesday June 29, 2021 @11:35AM (#27677394)
Thanks!

Could you use your Java code to define Factorial?