Am Sonntag, 16. Dezember 2007 04:07 schrieb Don Stewart: > ------------------------------------------------------------------------ > Program 7: > > ============================== > hs/space-xxxxx-foldl.hs: > {-# LANGUAGE BangPatterns #-} > > cnt :: String -> Int > cnt bs = foldl (\sum c -> if c == ' ' then sum+1 else sum) 0 bs > > main = do s <- getContents > print (cnt s) > > Hmm. Lazy accumulator eh, on String? Should exhibit a space leak.
Doesn't (with -O2, at least), seems ghc's strictness analyser did a good job. It is indeed about 10* slower than ByteStrings, but very memory friendly - and, actually on my machine it's faster (not much) than Data.List.foldl' . And, again on my machine, Programme 3 is almost as slow when compiled with 6.8.1 and twice as slow when compiled with 6.6.1. > Nice little benchmark. > > -- Don Cheers, Daniel _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe