(, . , -, )
, , λg(x) , -. , -, , - , . , , , . , . - :
λarg.body
. λ ( "", ), , , , , . , identity, - , :
λx.x
- . :
function-or-expression arg-or-expression
" , . , arg-or-expression body . , , arg-or-expression . λx.x (λy.y 0) ( , - 0, - ):
λx.x (λy.y 0)
=> λx.x 0
=> 0
λx.x (λy.y 0)
=> λy.y 0
=> 0
λx.x. λx.x - . , " " - () , . , , . - , , . , ( ) .
- , , . . , . , , -:
λname(arg).body
, , λarg.body name, - - name λarg.body. :
λidentity(x).x
, identity, λx.x. . , ?
λevil(x).(evil x)
. , evil body , . λx.(evil x), :
λevil(x).(evil x)
=> λevil(x).(λx.(evil x) x)
=> λevil(x).(λx.(λx.(evil x) x) x)
=> ...
. , -. -, "replace evil, evil ". , .
, -, . , , - :
λx.(x x)
identity, :
λx.(x x) λx.x
=> λx.x λx.x
=> λx.x
self:
self identity
=> identity identity
=> identity
, self ?
λx.(x x) λx.(x x)
=> λx.(x x) λx.(x x)
=> λx.(x x) λx.(x x)
=> ...
, self self self self . , (Turing-complete).
, -. , , . λevil(x).(evil x) -, -. " " , , , . (, , .)
, - Y-combinator. , evil , , , , body :
λevil(f).λy.(f y)
evil identity, , identity. → , = > :
(evil identity) 0
-> (λf.λy.(f y) identity) 0
-> (λf.λy.(f y) λx.x) 0
=> λy.(λx.x y) 0
=> λx.x 0
=> 0
, evil identity:
(evil evil) 0
-> (λf.λy.(f y) λf.λy.(f y)) 0
=> λy.(λf.λy.(f y) y) 0
=> λf.λy.(f y) 0
=> λy.(0 y)
, , - - . (evil (evil evil)), . (evil (evil (evil evil))), . , , evil , , - . , - . , Y-combinator:
λf.(λx.(f (x x)) λx.(f (x x)))
, , Y , , :
Y evil
-> λf.(λx.(f (x x)) λx.(f (x x))) evil
=> λx.(evil (x x)) λx.(evil (x x))
=> evil (λx.(evil (x x))
λx.(evil (x x)))
=> evil (evil (λx.(evil (x x))
λx.(evil (x x))))
=> evil (evil (evil (λx.(evil (x x))
λx.(evil (x x)))))
, , . evil, , evil, . , " " evil, evil (Y evil). , , , :
λname(x).(.... some body containing (name arg) in it somewhere)
:
λname-rec(f).λx.(...... body with (name arg) replaced with (f arg))
λname(x).((name-rec (Y name-rec)) x)
, , Y name-rec , .
, , waaaaay , , name-rec (Y name-rec) Y name-rec, . . , Y name-rec , , name-rec - , , Y name-rec, , .
, , . , . , x = 3, x = 5, , x, 3, x 5. , "" , x 5. , , , . , , .
, , . , - . , , , .
Racket, , , Racket "" ( ), , Racket , , (promise ...). Haskell , " ", , , , .
, , , , , , . , , , , .