cba4ffd80b02304f48486519d1f7c411ecdc4f44
[packages/containers.git] / Utils / Containers / Internal / StrictFold.hs
1 {-# LANGUAGE CPP #-}
2 #if !defined(TESTING) && __GLASGOW_HASKELL__ >= 703
3 {-# LANGUAGE Safe #-}
4 #endif
5
6 #include "containers.h"
7 {-# OPTIONS_HADDOCK hide #-}
8
9 module Utils.Containers.Internal.StrictFold (foldlStrict) where
10
11 -- | Same as regular 'Data.List.foldl'', but marked INLINE so that it is always
12 -- inlined. This allows further optimization of the call to f, which can be
13 -- optimized/specialised/inlined.
14
15 foldlStrict :: (a -> b -> a) -> a -> [b] -> a
16 foldlStrict f = go
17 where
18 go z [] = z
19 go z (x:xs) = let z' = f z x in z' `seq` go z' xs
20 {-# INLINE foldlStrict #-}