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,...).