tag:blogger.com,1999:blog-6264947694886887540.post8197215793343800639..comments2024-03-27T22:51:35.227-07:00Comments on Ken Shirriff's blog: The Y Combinator in Arc and JavaKen Shirriffhttp://www.blogger.com/profile/08097301407311055124noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-6264947694886887540.post-70050189449079917292018-01-18T18:04:48.097-08:002018-01-18T18:04:48.097-08:00Tom: FuncToIntFunc is an interface, not a function...Tom: FuncToIntFunc is an interface, not a function.Ken Shirriffhttps://www.blogger.com/profile/08097301407311055124noreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-8156707687879112772018-01-18T04:42:29.412-08:002018-01-18T04:42:29.412-08:00@saka1029: Note that your definition of FuncToIntF...@saka1029: Note that your definition of <b>FuncToIntFunc</b> is recursive. So, your construction has not avoided recursion in the definition of the factorial function.Anonymoushttps://www.blogger.com/profile/17746793826979090363noreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-50676653394640453452015-04-24T17:45:18.532-07:002015-04-24T17:45:18.532-07:00In java8
import java.util.function.Function;
cla...In java8<br /><br />import java.util.function.Function;<br /><br />class YFact {<br /><br /> interface FuncToIntFunc<br /> extends Function<FuncToIntFunc, Function<Integer, Integer>> { }<br /><br /> public static void main(String args[]) {<br /> FuncToIntFunc SELF = f -> f.apply(f);<br /> Function<Function<Function<Integer, Integer>, Function<Integer, Integer>>,<br /> Function<Integer, Integer>> Y =<br /> r -> SELF.apply(f -> r.apply(x -> f.apply(f).apply(x)));<br /> System.out.println(Y<br /> .apply(f -> n -> n == 0 ? 1 : n * f.apply(n - 1))<br /> .apply(Integer.parseInt(args[0])));<br /> }<br />}<br />Anonymoushttps://www.blogger.com/profile/10453332296774281857noreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-91719350372146521562015-04-24T17:40:41.324-07:002015-04-24T17:40:41.324-07:00This comment has been removed by the author.Anonymoushttps://www.blogger.com/profile/10453332296774281857noreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-31353849601374192502015-03-18T22:02:06.622-07:002015-03-18T22:02:06.622-07:00Anonymous: thanks for pointing out the typo. I'...Anonymous: thanks for pointing out the typo. I've fixed it.Ken Shirriffhttps://www.blogger.com/profile/08097301407311055124noreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-14542236430014908502015-03-17T07:52:24.148-07:002015-03-17T07:52:24.148-07:00weird typo in the yellow-highlighted code. It read...weird typo in the yellow-highlighted code. It reads<br />"return f.apply(f;) }})"<br />but I guess should be<br />"return f.apply(f); }})"Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-44522884531297834512012-05-01T15:22:16.428-07:002012-05-01T15:22:16.428-07:00Came across this post years late, but you can do a...Came across this post years late, but you can do a generic Java version that's actually a bit simpler than what you have above. The only interfaces you need are Func and FuncToTFunc. I've also formatted the code so it's more Java-ish<br /><br />https://gist.github.com/2571928<br /><br />Java 8's improved closure syntax will make this a lot more readable, too.Jon Bodnernoreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-30536839598899051672009-06-08T15:43:57.573-07:002009-06-08T15:43:57.573-07:00It's actually not too terribly hard to use jav...It's actually not too terribly hard to use java generics to get a version of the Y combinator which isn't limited to int->int functions.<br /><br />I did this about a year ago: http://dtm.livejournal.com/36832.htmlAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-28178079190329078862009-03-02T14:06:00.000-08:002009-03-02T14:06:00.000-08:00You might be interested in Functional Java which i...You might be interested in Functional Java which implements other crazy stuff in Java.Tony Morrishttps://www.blogger.com/profile/17206456907461293947noreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-67359072867410203782009-03-02T07:08:00.000-08:002009-03-02T07:08:00.000-08:00Y0 dawg, I herd you like closures in your... Ah sc...Y0 dawg, I herd you like closures in your... Ah screw it, this is just madnessAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-71512942200511345242009-03-02T07:02:00.000-08:002009-03-02T07:02:00.000-08:00Anonymous, the difficulty in understanding how the...Anonymous, the difficulty in understanding how the Y combinator works has basically nothing to do with the variable names used. I promise that you wouldn't find it any easier with different names.Gareth McCaughanhttps://www.blogger.com/profile/05377158305586280009noreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-44497133169326902672009-03-02T06:53:00.000-08:002009-03-02T06:53:00.000-08:00hey! listen mister! you guys can you guys can you ...hey! listen mister! you guys can you guys can you guys just use real variable names please this is hard to this is kind of hard to understand<BR/><BR/>thanks guysAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-85465367867577150172009-03-02T06:49:00.000-08:002009-03-02T06:49:00.000-08:00System.out.println(new Object() { public int fac(i...System.out.println(new Object() { public int fac(int x) { return x < 2 ? x : x * fac(x - 1); } }.fac(5));<BR/><BR/>Not Y, but a reasonable approach to reasonably anonymous recursion in an unreasonable language.Ricky Clarksonhttps://www.blogger.com/profile/13845104548520132930noreply@blogger.comtag:blogger.com,1999:blog-6264947694886887540.post-26547753835263750262009-03-02T06:47:00.000-08:002009-03-02T06:47:00.000-08:00Same thing in C# - http://blogs.msdn.com/madst/arc...Same thing in C# - http://blogs.msdn.com/madst/archive/2007/05/11/recursive-lambda-expressions.aspxAnonymousnoreply@blogger.com