On Jan 30, 2008 11:05 AM, Gracjan Polak <[EMAIL PROTECTED]> wrote: > My strictness analyser in my brain hurts. Which one (foldl,foldl',foldr) is > the > best way? > > Prelude Data.Set Data.List> let s = fromList [1,2,3,4,5] > Loading package array-0.1.0.0 ... linking ... done. > Loading package containers-0.1.0.0 ... linking ... done. > > Prelude Data.Set Data.List> foldl (.) id > (Data.List.map Data.Set.delete [1,3,5]) s > fromList [2,4] > > Prelude Data.Set Data.List> foldl' (.) id > (Data.List.map Data.Set.delete [1,3,5]) s > fromList [2,4]
I think this one. Map and Set are strict in their keys, so using foldl' won't lose you any generality and will be stricter (so hopefully faster). My internal heuristic is this: foldr when you can get some of the information without computing the whole result, foldl' when you can't, and never use foldl. Luke _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
