Ticket #4507: sumprod.diff

File sumprod.diff, 823 bytes (added by pozorvlak, 3 years ago)

Patch containing efficient versions of Data.List.sum and Data.List.product

Line 
1*** List.old    2010-11-17 15:28:16.000000000 +0000
2--- libraries/base/Data/List.hs 2010-11-17 15:29:26.000000000 +0000
3***************
4*** 1011,1024 ****
5  sum                     =  foldl (+) 0
6  product                 =  foldl (*) 1
7  #else
8! sum     l       = sum' l 0
9!   where
10!     sum' []     a = a
11!     sum' (x:xs) a = sum' xs (a+x)
12! product l       = prod l 1
13!   where
14!     prod []     a = a
15!     prod (x:xs) a = prod xs (a*x)
16  #endif
17 
18  -- -----------------------------------------------------------------------------
19--- 1011,1018 ----
20  sum                     =  foldl (+) 0
21  product                 =  foldl (*) 1
22  #else
23! sum                     =  foldl' (+) 0
24! product                 =  foldl' (*) 1
25  #endif
26 
27  -- -----------------------------------------------------------------------------