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. DVSSZQIQ
    LZPO@LBP@XFEEJOH
    !LBU[DIBOH

    View full-size slide

  2. 21)1͸޷͖Ͱ͔͢ʁ

    View full-size slide

  3. 21)1͸޷͖Ͱ͔͢ʁ

    View full-size slide

  4. ʊਓਓਓਓਓਓਓਓਓਓਓਓਓʊ
    ʼɹಥવ4USJOH͕*OUʹมΘΔɹʻ
    ʉ:?:?:?:?:?:?:?:?:?:ʉ

    View full-size slide

  5. ʮྫ͑͹ɺ1)1Λආ͚Δʯ

    View full-size slide

  6. IUUQKBXJLJQFEJBPSHXJLJ&&"&"&"#3BTNVT@-FSEPSG@DSPQQFEKQH

    View full-size slide

  7. 1)1JTBCPVUBTFYDJUJOHBTZPVSUPPUICSVTI
    :PVVTFJUFWFSZEBZ JUEPFTUIFKPC
    JUJTBTJNQMFUPPM TPXIBU
    IUUQFOXJLJRVPUFPSHXJLJ3BTNVT@-FSEPSG

    View full-size slide

  8. 「PHPは、歯ブラシみたいなものですね。
    毎日使うものですけど、だから何でしょう?」
    IUUQBOPOEIBUFMBCPKQ

    View full-size slide

  9. ແ໊ؔ਺͕͋Δ
    ˞+BWBҎલͱͷൺֱ

    View full-size slide

  10. $f = function($a, $b) {
    return $a + $b;
    };
    echo $f(2,3); // => 5

    View full-size slide

  11. $f = (function($a, $b) {
    return $a * $b;
    })(2,3); // FAIL!!!

    View full-size slide

  12. $fib = function($x) {
    return $x < 2
    ? $x
    : $fib($x-1) + $fib($x-2);
    }));
    echo $fib(6); // FAIL!!

    View full-size slide

  13. IUUQTHJTUHJUIVCDPNLBU[DIBOH

    ˞༵ۚ೔ޕޙͰ͢

    View full-size slide

  14. $f = F::curry(
    function($_) {
    return $_[0] + $_[1];
    });
    echo $f->_(2)->_(3)->_();

    View full-size slide

  15. IUUQTHJTUHJUIVCDPNBKJZPTIJWH
    CBECEF
    ˞༵ۚ೔ޕޙͰ͢

    View full-size slide

  16. $c = curry(
    function($a, $b){
    return $a + $b;
    });
    echo $c->_(2)->_(3);

    View full-size slide

  17. function YComb($f) {
    $yc = curry(
    function($y, $x)
    use ($f) {
    return $f($y($y), $x);
    });
    return $yc($yc);
    }

    View full-size slide

  18. echo (YComb(curry(
    function($f, $x){
    return $x < 2
    ? $x
    : $f($x-1) + $f($x-2);
    })))->_(6);

    View full-size slide

  19. ʮ͜Ε͸ɺࣃϒϥγͱͯ͠΋࢖͍෺ʹͳΔϨϕϧʯ

    View full-size slide