Real World Haskell - 第4章 Part7 How to think about loops (続き)
Real World Haskell で Haskell を継続的に勉強中。
Chapter 4. Functional programming
Chapter 4. Functional programming
How to think about loops
Left folds, laziness, and space leaks
- foldl は space leak を起こすので thunk を作らない foldl' を使うべし
ghci> foldl (+) 0 [1..1000000] *** Exception: stack overflow ghci> :module +Data.List ghci> foldl' (+) 0 [1..1000000] 500000500000