|
inits: msg#00017lang.haskell.libraries
Earlier today on the #haskell IRC channel, Tim Toorop (bolrod on #haskell) pointed out that Data.List.inits is rather slow, and proposed an alternative. After some collabrative tweaking, we came up with the following: > inits xs = [] : (zipWith take [1..] $ map (const xs) xs) This function seems to perform significantly better. For example, the program below takes about 15 seconds with the old inits, and only 3 seconds with the new version (tested with GHC 6.4.1 and -O2). > main = print $ sum $ map sum $ inits [1..7000] As this version performs much better and will work as a drop in replacement, I suggest that it be included in the hierarchical libraries. Spencer Janssen |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Parsec parser for Java?: 00017, Punyashloka Biswal |
|---|---|
| Next by Date: | Re: inits: 00017, Sebastian Sylvan |
| Previous by Thread: | Parsec parser for Java?i: 00017, Punyashloka Biswal |
| Next by Thread: | Re: inits: 00017, Sebastian Sylvan |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | Mail Home | sitemap | FAQ | advertise |