

Three Little Birds – Deriving the Y Combinator - eggsby
http://samesake.com/log/2013/01/03/Three-little-birds/
Just what the world needs, another post explaining the y combinator! Hope someone can glean some information from this, I learned a fair bit in writing it :)
======
brianberns
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.

~~~
eggsby
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 :)

~~~
brianberns
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.

------
raganwald
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.

~~~
eggsby
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>

------
tesmar2
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.

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

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

