Thu, 27 May 1999 09:16:43 +0400 (MSD), S.D.Mechveliani <[EMAIL PROTECTED]> pisze:

> And  sm  is the implementation of  sum  shown in  src/.../PrelList.lhs

ghc/lib/std/PrelList.lhs from ghc-4.02 sources:
>>>>>>>>
-- sum and product compute the sum or product of a finite list of numbers.
{-# SPECIALISE sum     :: [Int] -> Int #-}
{-# SPECIALISE product :: [Int] -> Int #-}
sum, product            :: (Num a) => [a] -> a
#ifdef USE_REPORT_PRELUDE
sum                     =  foldl (+) 0  
product                 =  foldl (*) 1
#else
sum     l       = sum' l 0
  where
    sum' []     a = a
    sum' (x:xs) a = sum' xs (a+x)
product l       = prod l 1
  where
    prod []     a = a
    prod (x:xs) a = prod xs (a*x)
#endif
<<<<<<<<

So `foldl (+) 0' is only for the report as far as I understand it.
The real implementation is different.

But I'm not sure why it makes a difference. Definition of foldl is
similar to sum', only with a different argument order:

>>>>>>>>
foldl                   :: (a -> b -> a) -> a -> [b] -> a
foldl _ z []            =  z
foldl f z (x:xs)        =  foldl f (f z x) xs
<<<<<<<<

-- 
 __("<    Marcin Kowalczyk * [EMAIL PROTECTED] http://kki.net.pl/qrczak/
 \__/       GCS/M d- s+:-- a22 C+++>+++$ UL++>++++$ P+++ L++>++++$ E->++
  ^^                W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP->+ t
QRCZAK                  5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-

Reply via email to