Upgrade to Pro — share decks privately, control downloads, hide ads and more …

curry.php

 curry.php

A functional programming using php.

Kazunori Otani

March 29, 2014
Tweet

More Decks by Kazunori Otani

Other Decks in Technology

Transcript

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

    $x : $fib($x-1) + $fib($x-2); })); echo $fib(6); // FAIL!!
  2. <?PHP function YComb($f) { $yc = curry( function($y, $x) use

    ($f) { return $f($y($y), $x); }); return $yc($yc); }
  3. <?PHP echo (YComb(curry( function($f, $x){ return $x < 2 ?

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