Mistakes occur in Haskell?

Haskell makes heavy use of recursion as a pure functional programming language. Errors occur in Haskell, as in Java? Why or why not?

+4
source share
2 answers

Haskell uses the stack differently from Java, due to laziness.

In Java, a stack frame is created when the method is called and freed when the method returns. Therefore, if it f()is a recursive method, each recursive call f()creates a stack frame, and these frames are strictly nested. You can get stack overflows when you have a deep chain of recursive calls, for example f() -> f() -> f() -> ….

Haskell , . , thunk (, case) , thunk , ( thunks).

, f , f thunk, case , , theres thunks. , seq: a `seq` b " a b, b", b on a, , b , a .

, , , foldl:

foldl (+) 0 [1..5]
==
foldl (+) 0 (1 : 2 : 3 : 4 : 5 : [])
==
((((0 + 1) + 2) + 3) + 4) + 5

, :

((+)
    ((+)
        ((+)
            ((+)
                ((+)
                    0
                    1)
                2)
            3)
        4)
    5)

(, ), , (+) 0 1 thunk.

foldl , foldl' ( ), - . , , foldl' (0+1 = 1, 1+2 = 3, 3+3 = 6,...).

+12

Haskell, Java, .., -.

Java C . , , , . , .

Haskell , . , GHC, Haskell . , thunks .

, haskell , . , .

(GHC thunk, . , , Java, C ..)

-1

Source: https://habr.com/ru/post/1674246/


All Articles