curry.php

 curry.php

A functional programming using php.

F2f9d54e8fafad3fce62bbf072cdab1e?s=128

katzchang

March 29, 2014
Tweet

Transcript

  1. 10.
  2. 13.
  3. 15.

    <?PHP $fib = function($x) { return $x < 2 ?

    $x : $fib($x-1) + $fib($x-2); })); echo $fib(6); // FAIL!!
  4. 16.
  5. 21.

    <?PHP function YComb($f) { $yc = curry( function($y, $x) use

    ($f) { return $f($y($y), $x); }); return $yc($yc); }
  6. 22.

    <?PHP echo (YComb(curry( function($f, $x){ return $x < 2 ?

    $x : $f($x-1) + $f($x-2); })))->_(6);
  7. 25.