codesnippets:folds
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| codesnippets:folds [2021/04/08 17:43] – f2b216 | codesnippets:folds [2025/10/08 00:48] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 327: | Line 327: | ||
| * large lists | * large lists | ||
| * order of operations to be kept as is foldr | * order of operations to be kept as is foldr | ||
| - | * executed with small impact on heap space | ||
| - | * fast to be executed, almost as foldl does | ||
| - | |||
| - | The implications regarding order of execution: | ||
| * example, using foldr:< | * example, using foldr:< | ||
| main :: IO () | main :: IO () | ||
| Line 342: | Line 338: | ||
| lnNumbers2 = [31,13,3] | lnNumbers2 = [31,13,3] | ||
| lnNumbers3 = [1..100000000] | lnNumbers3 = [1..100000000] | ||
| - | + | ||
| f1 :: [Integer] -> Integer | f1 :: [Integer] -> Integer | ||
| - | f1 ln = foldr (-) 1 ln | + | f1 ln = foldr (-) 0 ln |
| </ | </ | ||
| * executes, with output:< | * executes, with output:< | ||
| Line 351: | Line 347: | ||
| -50000000 | -50000000 | ||
| </ | </ | ||
| - | | + | * executes within approximately __**15 seconds**__ on Intel(R) Core(TM) i5-8400 @ 2.80GHz |
| + | * executes using large heap space | ||
| + | * {{: | ||
| + | | ||
| import qualified Data.List as L | import qualified Data.List as L | ||
| Line 375: | Line 374: | ||
| 21 | 21 | ||
| -50000000 | -50000000 | ||
| + | </ | ||
| + | * executes within approximately __**15 seconds**__ on Intel(R) Core(TM) i5-8400 @ 2.80GHz | ||
| + | * executes using large heap space | ||
| + | * {{: | ||
| + | * regardless of whether '' | ||
| + | * regardless of whether alternative '' | ||
| + | * e.g.:< | ||
| + | reverse' | ||
| + | reverse' | ||
| + | where | ||
| + | reverse'' | ||
| + | reverse'' | ||
| + | reverse'' | ||
| + | </ | ||
| + | * or<code Haskell> | ||
| + | reverse' | ||
| + | reverse' | ||
| + | </ | ||
| + | * or<code Haskell> | ||
| + | reverse' | ||
| + | reverse' | ||
| </ | </ | ||
| Line 386: | Line 406: | ||
| * if the initial value is the first and the last respectively use '' | * if the initial value is the first and the last respectively use '' | ||
| + | |||
| + | ===== ✎ ===== | ||
| + | ~~DISCUSSION~~ | ||
codesnippets/folds.1617896624.txt.gz · Last modified: (external edit)
