Last active
October 1, 2016 22:34
-
-
Save i-am-tom/692c0f44ef2880973fdcb1875fd80248 to your computer and use it in GitHub Desktop.
The Y (and U) combinator(s), with an example, implemented in PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fib = function ($f) { | |
return function ($n) use ($f) { | |
switch ($n) { | |
case 0: return 0; | |
case 1: return 1; | |
default: | |
return $f ($n - 1) | |
+ $f ($n - 2); | |
} | |
}; | |
}; | |
Y ($fib) (10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function U ($f) { | |
return $f ($f); | |
} | |
function Y ($f) { | |
return U (function ($x) use ($f) { | |
return $f (function ($y) use ($x) { | |
return U ($x) ($y); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment