Functional "simultaneity"?

This link talks about functional programming. In particular, the author says the following:

Simultaneity means that we assume that the statement in the lambda calculus is evaluated immediately. Trivial function:

λf(x) ::= x f(x)

defines an infinite sequence of what you connect for x. Step-by-step expansion is as follows:

0   - f(x)
1   - x f(x)
2   - x x f(x)
3   - x x x f(x)

The fact is that we must assume that the "f ()" and "x" in the three million step have the same meaning as in the first stage.

At this point, those of you who know something about FP are struggling with “link transparency” under your collective breath. I know. In a minute I will beat it. For now, just suspend your distrust in order to acknowledge that the restriction exists and the hardware will not suffer.

The problem with endless extensions in a real computer is that ... well .. they are endless. As in, an infinite loop is infinite. You cannot evaluate each term in an infinite sequence before proceeding to the next evaluation, unless you plan a really long coffee break while you wait for answers.

Fortunately, theoretical logic comes to the rescue and tells us that a preliminary assessment always gives us the same results as a post-order evaluation.

More vocabulary .. need another function for this .. fortunately, it is simple:

λg(x) ::= x x

... :

g(f(x))

, f (x), g(). , . , :

0   - g(f(x))
1   - f(x) f(x)
2   - x f(x) x f(x)
3   - x x f(x) x x f(x)

., - , ? , . , FP, .

+4
1

(, . , -, )

, , λ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 , " ", , , , .

, , , , , , . , , , , .

+1

All Articles