Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

How the christ does the Y Combinator work?

Name: Anonymous 2010-10-20 22:39

Fuck, I've been rereading http://mvanier.livejournal.com/2897.html for the past several hours and it might as well be written in Esperanto. Am I just not cut out for EXPERT PROGRAMMING

Name: Anonymous 2010-10-20 23:07

>>1
Lambda erectus walks on two legs, preferably identical. But why does he stand on his head?

Name: Anonymous 2010-10-20 23:41

>>1
I wouldn't worry about it too much. Functional programming is of no real-world value. No one cares but for a few arrogant ivory tower academics.

Name: Anonymous 2010-10-20 23:46

The website or the community?

Name: Anonymous 2010-10-20 23:59

Y combinator is a rather simple way to represent recursion, however you won't really need to use it in practice, unless you're working with a language which doesn't support recursion, but supports first class functions, which is something rather rare and only encountered in more theorethical languages (like pure lambda calculus).

I don't really understand why you have trouble understanding the Y combinator, maybe it's because you don't know Scheme or Common Lisp well enough? Even so, you should be able to understand it, since one can express it in very small subsets of Scheme or CL, or even simpler languages like pure lambda calculus.

Name: Anonymous 2010-10-21 5:46

the Y-combinator is just a δ-rule added to the typed lambda-calculus in order to make recursion work again.
which was broken by introducing types to the lambda-calculus

Name: Anonymous 2010-10-22 13:20

>>6
I'll bite. How can you define recursion in untyped lambda-calculus then -- wouldn't that be by using something like the Y combinator?

Name: forgot my bump 2010-10-22 13:20

Name: Anonymous 2010-10-22 14:16

>>7
no. please read the books yourself, ``faggot''.

Name: Anonymous 2010-10-22 14:58

>>9
Fuck off, ``please''.

Name: Anonymous 2010-10-22 20:05

>>9
This may surprise you, but I invented the ``faggot'' meme, ``faggot''.

Name: Anonymous 2010-10-22 21:17

>>11
Kill yourself, asshole .

Name: Anonymous 2010-10-22 21:21

>>12
This may surprise you, but I invented the ``Kill yourself'' meme.

Name: Anonymous 2010-10-22 21:37

>>13
This may surprise you, but ``Kill yourself'' isn't a meme. ``Faggot.''

Name: Anonymous 2010-10-22 21:39

>>13
(This-may-surprise-you,-but (Y This-may-surprise-you,-but))

Name: Anonymous 2010-10-23 1:23

Name: Anonymous 2010-10-23 1:56

Wait a second...

So Y is just a fancy way to write ff=Y(f); ff(arg) (forgive my C roots) instead of f(f,arg)?

Wow. And I thought is was something serious.

Name: Anonymous 2010-10-23 5:17

>>16
Cool, thanks. From what I understand, the Y combinator is simply a way of circumventing the need for globals when defining a recursive function.

Name: Anonymous 2010-10-23 5:23

Not globals, just named functions.

Name: Anonymous 2010-10-23 7:22

>>17
It's a fancy way to write ff=Y(f); ff(arg) instead of f(f(f(f(f(f(f(f(f(f(f(f(f(f(...ff...))))))))))))), arg).

Name: Anonymous 2010-10-23 8:26

>>20
Uh..

Here, check this perl code out. $fact contains an anonymous recursive function not using anything outside of its scope. $y_fact is the same thing only with Y.

my $fact=sub{
    my($func,$arg)=@_;
   
    return 1 if $arg==0;
   
    return $arg*$func->($func,$arg-1)
};

my $y=sub{
    my($func)=@_;
   
    return sub{
        return $func->($func,@_);
    }
};

print $fact->($fact,5),"\n"; # prints 120

my $y_fact=$y->($fact);
print $y_fact->(5),"\n";     # prints 120, too. So much for Y combinator...


The only difference from paper someone linked to is that my function accepts two arguments at once while their accepts one and returns a function that accepts another one (but the dead dog taught us this is the same thing).

Name: FrozenVoid meme fan 2010-10-23 9:30

function Y(f) {
  function g(h) {
    return function(x) {
      return (f(h(h)))(x);
    };
  }
  return g(g);
}

Name: Anonymous 2010-10-23 9:36

>>21
The difference is that your recursive case uses f(f, arg-1) where the recursive case with a real Y combinator would be f(arg-1), abstracting out finding the fixed point from computing the factorial. Having Y proves constructively that every function has at least one fixed point (in the context of untyped lambda calculus).

Name: Anonymous 2010-10-23 11:05


def factorial (n):
    if n == 0:
        return 1
    else:
        return n * factorial (n-1)


Just wanted to show you recursion

Name: 24 2010-10-23 11:05

In Python.

Name: Anonymous 2010-10-23 11:08

>>24,25
spaces before parentheses
missing point of thread
not sageing

Get the fuck out.

Name: Anonymous 2010-10-23 11:30

>>26
HYBT?

Name: Anonymous 2010-10-23 11:37

>>23
Practically though, this is only syntactic sugar. Any function that can be written your way can also be written my way. The only difference that in each call to my function I have to specify it as first argument. Y is a wrapper that does it for me by putting that function I otherwise would have to specify myself into environment of function it returns. If you're >>20 I want you to apologize for the nonsense you wrote without thinking.

Name: Anonymous 2010-10-23 11:53

>>26
no u

Name: Anonymous 2010-10-23 11:54

>>28
fuck you I won't do what you tell me

Name: Anonymous 2010-10-23 13:55

>>17,20,21,28,etc
If you want to know why it's important, read the following keeping in mind that the constraints encountered are not arbitrary:
http://www.ps.uni-sb.de/courses/sem-prog97/material/YYWorks.ps

>>28:
Practically though, this is only syntactic sugar.
Terrible!

Name: Anonymous 2010-10-23 16:53

>>31
Well this was pretty informative. I had no idea that Socrates was such a wiz at lambda calculus.

Name: Anonymous 2010-10-23 19:42

>>32
Socrates? I think you mean a certain Tortoise who liked to school a certain Achilles.

Name: Anonymous 2010-10-29 10:29

>>21
Come on, this is Perl, not PHP; s/,/, /g; s/==?|\*/ $& /g;

Name: Anonymous 2011-02-04 13:03

Name: Anonymous 2013-11-05 1:47

That's interesting, I thought that Y Combinator was the Project Runway of le bay coders

Name: Anonymous 2013-11-05 2:02

http://en.wikipedia.org/wiki/Fixed-point_combinator#Explanation_for_imperative_programmers

why no
factorial(integer n) {
int k=1;
int i=0;
for(i=1; i<=n; i++){
  k*=i;
  }
return k;
}

Name: Anonymous 2013-11-05 2:17

Name: Anonymous 2013-11-05 3:01

*YOU HAVE BEEN VISITED BY LE TOP LEL OF COMEDY GOLD** POST THIS IN 3 threads or lose your sides!
░░░░░░░▄▀▀▀░▄▄▄▄░░░▀▀▀▀▀▀▀▀▄▄░▀
░░░░░░░█░░░░░░░░▀▀▀▀▀▄▄▄▄▄▄▄▄▀░░█
░░░░░▄▀░░░░░░░░░░▄░░░░░░░░▄▄░░░░░▀▄
░░░▄▀░░░░░▄▀▀▀█▄░▀░░░░▄▀▀▀██▀▀▄░░░░░▀
░░▄▀░░▄▄░░▀▀▀▀████▀░░░▀▄▄▀▀▀▀▄█░░░░░░█
░▄▀░▄▀█░░▄▄░░░░░░░█░░░░░▄▄▄░░░▀▀░░░░░░█
▄▀░░█░█░▀░░▀▀▄░░░░░█░░░░░░░▀▀▀▀▀▄░░░░░█
▀▄░░▀░█░░░▄░░░░░░▄▀░░░░▀▄░░░▄▄░░▀▄░█░▄▀
░░▀▄░░░░█▀▄░░░░░▀█░░░░▀▀░█▄▀▄░█░░░█░█
░░░░█░░█░▀▄▀▄▄░░░░▀▀▀░░░▄█▀░▄▀█░░░░▄
░░░░░█░░█░▀▀▄░▀▄▄▄▄▄▄▄▀█░▄█▀▄▀░░░░░
░░░░░█░░▀▄▄░░▀█░░░█░░▄▄▀▀▄▄█▀░░░░▀
░░░░▄▀░░░▀▄▀▀▄░▀▀▀▀▀▀▄▄▀▀▀▄▀░░░░▀
░░░▄▀░░░░░░▀▄░█▄▄▄▄▀▀░▀▄▀▀░░░▄▀▀
░░▄▀░░░░░░░░░▀▄▄▄▄█▄▄▀▀░░░░▄
░░█░░░░░░▀▄▄░░░▄▄▄▄▄▄▀░░░▄▀
░░█░░░░░░░░░▀▀▀▄▄▄▄▄▄▄▀▀
░░░█░░░░░░▀▀▀▀▀░░░░▄
░░░▀▀▄▄▄▄▄▄▄▄▄▀▀▀

Name: Anonymous 2013-11-05 15:54

>>39
That's why it's called a paradox.

Name: Anonymous 2013-11-06 2:05

A boy died in 1932 by a homicidal murderer. He buried him in the ground when he was still alive. The murdered chanted, "Toma sota balcu" as he buried him. Now that you have read the chant, you will meet this little boy. In the middle of the night he will be on your ceiling. He will suffocate you like he was suffocated. If you post this, he will not bother you. Your kindness will be rewarded.

Name: Anonymous 2013-11-06 21:31

>>1
It's magic. I ain't GOTO explain shit!

Name: Anonymous 2013-11-07 4:58

>>3

This. Academia circle jerk discovered blogging and now we have a retarded FP hype.

Name: Anonymous 2013-11-07 5:02

it's shit

Name: Anonymous 2013-11-07 23:47

How the christ does the Y Combinator work?

The Ways of God are Inscrutable.

Name: Anonymous 2013-11-08 16:12

I am enlightened.

Don't change these.
Name: Email:
Entire Thread Thread List