
Untitled
By: a guest on
Aug 9th, 2012 | syntax:
None | size: 0.48 KB | hits: 6 | expires: Never
Can a thunk be duplicated to improve memory performance?
let xs = [1..10000000]
bad = do
print $ foldl1' (+) xs
print $ length xs
good = do
(xs1,xs2) <- copyThunk xs
print $ foldl1' (+) xs1
print $ length xs2
xsFunction :: () -> [Int]
xsFunction = const [1..10000000]
better = do
print $ foldl1' (+) $ xsFunction ()
print $ length $ xsFunction ()
let xs () = [1..1000000]
good = do
print $ foldl1' (+) (xs ())
print $ length (xs ())