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

不動点コンビネータ?

yubessy
March 26, 2018

 不動点コンビネータ?

社内勉強会用資料です

yubessy

March 26, 2018
Tweet

More Decks by yubessy

Other Decks in Programming

Transcript

  1. Q1.

  2. A1. for (var p = 1, n = 1; n

    <= 5; n++) p *= n p // -> 120
  3. Q2.

  4. A2. var f = n => n == 0 ?

    1 : n * f(n - 1) f(5) // -> 120
  5. Q3.

  6. A3. ※ (g => (h => g(y => h(h)(y)))(h =>

    g(y => h(h)(y)))) (f => n => n == 0 ? 1 : n * f(n - 1)) (5) (g => (h => g(y => h(h)(y)))(h => g(y => h(h)(y))))(f => n => n // -> 120
  7. Z = g => (h => g(y => h(h)(y)))(h =>

    g(y => h(h)(y))) g = f => n => n == 0 ? 1 : n * f(n - 1) x = 5 g A2 f = n => n == 0 ? 1 : n * f(n - 1)
  8. Z Z(g) = g(Z(g)) Z(g)(5) = g(Z(g))(5) = (f =>

    n => n == 0 ? 1 : n * f(n - 1))(Z(g))(5) = (n => n == 0 ? 1 : n * (Z(g))(n - 1))(5) = 5 == 0 ? 1 : 5 * (Z(g))(5 - 1) = 5 * (Z(g))(4) = ... = 5 * 4 * 3 * 2 * 1 ※ 3 Z(g)
  9. Z = g => (h => g(y => h(h)(y)))(h =>

    g(y => h(h)(y))) Z(g) = g(Z(g)) Z(g) = (g => (h => g(y => h(h)(y)))(h => g(y => h(h)(y))))(g) = (h => g(y => h(h)(y)))(h => g(y => h(h)(y))) = (h => g(x => h(h)(x)))(h => g(y => h(h)(y))) // α- = g(x => (h => g(y => h(h)(y)))(h => g(y => h(h)(y)))(x)) = g((h => g(y => h(h)(y)))(h => g(y => h(h)(y))) // η- = g(Z(g))
  10. (g => (h => g(y => h(h)(y)))(h => g(y =>

    h(h)(y)))) (f => n => n == 0 ? 1 : n * f(n - 1)) (5) = = fix(g) = g(fix(g)) fix Z ※
  11. ->

  12. ->

  13. (g => g(g))(f => n => n == 0 ?

    1 : n * f(f)(n - 1))(5) g => g(g)
  14. toolbox Haskell \f -> f f \g -> (\h ->

    g (h h)) (\h -> g (h h)) \f -> \n -> if n == 0 then 1 else n * f(n - 1) newtype Rec a = In { out :: Rec a -> a } \f -> (\x -> f (out x x)) (In (\x -> f (out x x))) \f -> \n -> if n == 0 then 1 else n * f(n - 1) OCaml (with -rectypes ) fun f -> f f fun g -> (fun h y -> g (h h) y) (fun h y -> g (h h) y) fun f n -> if n == 0 then 1 else n * f(n - 1)