Real World Haskell - 第4章 Part12 Space leaks and strict evaluation
Real World Haskell で Haskell を継続的に勉強中。
Chapter 4. Functional programming
Chapter 4. Functional programming
Space leaks and strict evaluation
- foldl 以外にも space leak が発生する場合がある
- seq で non-strict evaluation をバイパスできる (strict になる)
- thunk が発生しないのだが、動作は余り理解できていない...
- seq はパターンマッチでオーバーヘッドが発生する
seq :: a -> t -> t
foldl' _ zero [] = zero foldl' step zero (x:xs) = let new = step zero x in new `seq` foldl' step new xs
It is perfectly reasonable to skip this section until you encounter a space leak “in the wild”.
ということなので、seq の存在は覚えておいて後ほど戻ることにする。