Inlining: unroll2.hs

File unroll2.hs, 729 bytes (added by claus, 10 years ago)

non-strict foldl, INLINE foldl PEEL 1 (+SAT) prevents stackoverflow

Line 
1{-# LANGUAGE MagicHash #-}
2{-# LANGUAGE CPP #-}
3import Prelude hiding (foldl)
4import GHC.Prim
5
6-- ~0.4s real DOPEEL+DOUNROLL
7-- ~0.4s real DOPEEL
8-- stackoverflow without
9main = print $ foldl (+) 0 [1..10000000::Int]
10
11#ifdef DOPEEL
12#ifdef DOUNROLL
13-- simulate INLINE foldl PEEL 1 UNROLL1 (+SAT)
14{-# INLINE foldl #-}
15foldl op n l = foldlW n l
16  where
17  foldlW n (a:b:t) = foldlW ((n`op`a)`op`b) t
18  foldlW n (a:t)   = foldlW (n`op`a) t
19  foldlW n []      = n
20#else
21-- simulate INLINE foldl PEEL 1 (+SAT)
22{-# INLINE foldl #-}
23foldl op n l = foldlW n l
24  where
25  foldlW n (h:t) = foldlW (n`op`h) t
26  foldlW n []    = n
27#endif
28#else
29foldl op n (h:t) = foldl op (h`op`n) t
30foldl op n []    = n
31#endif
32