Hacker News new | past | comments | ask | show | jobs | submit login
Three Little Birds – Deriving the Y Combinator (samesake.com)
74 points by eggsby on Jan 4, 2013 | hide | past | favorite | 11 comments



As a professional programmer with a strong interest in functional programming, but none of the formal background, I should be the perfect reader for this article. Unfortunately, I found it to be a complete syntactic and semantic mess. I'll enumerate a few of the problems that tripped me up as I read:

* The underlying metaphor is poorly explained. E.g. The identity bird: "when you call out a bird to it it simply calls that bird back to you". The notion of "calling out a bird" is awkward and confusing. On first reading, it seems to imply that one calls out the name of a bird, which is simply wrong. I understand that birds represent higher-order functions, but if I didn't, I would never grasp it from reading this article. (I doubt that Smullyan was this sloppy in his original description of the metaphor.)

* The mockingbird "duplicates its input". No, it doesn't. It applies its input to itself, which is totally different from duplicating it. The next sentence is also confusing at best: "If you call some bird x to the mockingbird it will call back as if the bird x had called out to itself". The phrase "as if" is wrong and misleading, and bird x is not calling out some unspecified value to itself. A better description is that the mockingbird function calls out bird x to bird x. That's a huge difference.

* I had to read this phrase about five times before I could parse it: "The mental giants who computed before computers spoke to this magical bird chiefly for this purpose". And once parsed and understood, it still fails to explain why we're suddenly talking about factorials instead of birds. What makes this bird metaphorically "mechanical" or "foreign" is mysterious. It just does factorials somehow because it doesn't "follow the rules of regular combinator birds but it will follow some". Come again?

* The next sentence is where I started to give up: "Initially we call the strange factorial out to the mockingbird, which calls back the same thing as calling the strange bird to itself". Is the "fact" variable supposed to be the strange factorial? What is the strange bird? None of this terminology actually appears in the function that is supposedly being explained here. I had to ignore the text and work out the purpose of the function myself.

I'm sure there's value in this metaphor - I love the other Smullyan books that I've read and have a lot of respect for his careful puzzle-making. But I'm afraid this article doesn't do him justice as written.


Thanks, I'll work on elucidating the metaphor and being explicit about what I mean when I say things like 'duplicates input' (uses the parameter more than once in it's body, this is a term from Smullyan), as well as clarifying some of the language.

I want to make the idea simple to parse by breaking it down into it's pieces, if it's noticeably hard to swallow (or as you said the commentary actually detracts from my code examples) then I did it wrong!

Edit: I changed some terminology and clarified the points you mentioned, hope this helps anyone who reads this in the future, thanks again for taking the time to leave feedback :)


Happy to help. I think you might also want to improve this phrase: "its impact on computer science cannot be understanded". Truly, I have not understanded it at all. :) Perhaps you meant "overstated"?

More importantly, I think that line 4 of strangeFact is a key concept that needs better explanation. Your current description ("What this does is bind the parameter fact to our strange factorial bird and return a function who knows how to do this again should it ever need another copy of itself") is confusing, IMHO. It's not clear what you mean by "should it ever need another copy of itself". It would be especially nice if you could explain this idea in terms of birds, rather than parameter bindings. Otherwise, the metaphor becomes rather superficial, I think.

I'll try to work through the rest of the article as well, time permitting.


I found http://www.arcfn.com/2009/03/y-combinator-in-arc-and-java.ht... a much clearer explanation of what the Y combinator is and why it's useful.


Thanks. That led me to a nice C# version here: http://blogs.msdn.com/b/madst/archive/2007/05/11/recursive-l...


Where did I misplace my +100 wand? Great post, combinators are a not-so-hidden passion of mine and they inspire a lot of really practical applications in JavaScript and Ruby.


Thanks! I actually got the bug to write this post from reading your wonderful js combinator book[1] over the holiday, which reminded me that I also had a copy of To Mock a Mockingbird in my to read pile.

When I got to the bit where Smullyan describes the first sage bird (He explains: "This is quite simple ... for any bird x, Θx = M(Lx). Since x is fond of M(Lx) and M(Lx) = Θx, then x is fond of Θx, which means that Θ is a sage bird."), I felt like I had been hit by a brick wall as it was anything but simple for me, having previously grasped at understanding the y combinator.

Only by understanding the discrete moving parts was I able to finally wrap my head around what was going on. Like many others when I had my a-ha! moment I wanted to share.

Thank you for making content like this digestible!

1: https://leanpub.com/javascript-allonge


Jim Weirich derives the Y combinator in pure Ruby here:

http://vimeo.com/45140590

EDIT: Correct video http://www.youtube.com/watch?v=FITJMJjASUs

It is some of the ugliest ruby code I have ever seen, but it was something amazing to watch happen live.


Nice, I enjoyed Jim's talk where he derived the combinator using clojure[1]. In it he referenced another talk that he cites as an influence, "Programming With Nothing"[2] by Tom Stuart where he writes fizzbuzz in ruby using only lambda application.

Finding the SKI calculus was a similar revelation to me, that such simple combinators could represent any lambda term is such a huge idea!

1: http://www.infoq.com/presentations/Y-Combinator

2: http://rubymanor.org/3/videos/programming_with_nothing/


Is the Ruby hiding in that video? I briefly skimmed it and all I saw was JavaScript.


You are correct, I edited the comment with the right video.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: