
24 Sep
2010
24 Sep
'10
5 p.m.
Am 24.09.2010 17:55, schrieb Christian Maeder:
I consider it useful, because the "natural" implementation:
prependToAll s = foldr (\ x r -> s : x : r) []
seems to leak without optimization.
"leak" is wrong. My Benchmarks fail without optimization. (see attached log.txt) Christian Bench.hs: import Criterion.Main testCase f = print . length . f ',' main = do let s = replicate 100000000 'A' print $ length s defaultMain [ bench "prepend" $ testCase prepend s , bench "prependToAll" $ testCase prependToAll s ] prependToAll :: a -> [a] -> [a] prependToAll s = foldr (\ x r -> s : x : r) [] prepend :: a -> [a] -> [a] prepend s l = case l of [] -> [] x : r -> s : x : prepend s r