Created
December 8, 2009 08:28
-
-
Save clairvy/251521 to your computer and use it in GitHub Desktop.
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 fix($f) { | |
return function($x) use ($f) { | |
return $f(fix($f), $x); | |
}; | |
}; | |
$map = function($f, $xs) { | |
$func = fix(function($sf, $ys) use ($f) { | |
if (count($ys) > 0) { | |
$y = array_shift($ys); | |
$a = $sf($ys); | |
array_unshift($a, $f($y)); | |
return $a; | |
} else { | |
return array(); | |
} | |
}); | |
return $func($xs); | |
}; | |
$double = function($x) {return $x * 2;}; | |
print_r($map($double, array(1,2,3))); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment