I tried to decide Duplicate each item in a Haskell List and make it like a complete program that writes a list to standard output
Here is my solution
main :: IO ()
main = getList >> = return. doubleEachItem >> = putStrLn. show
getList = return [1,3,5]
doubleEachItem :: [Int] -> [Int]
doubleEachItem = foldr (++) []. map (take 2. repeat)
But when I try to process a really long list
getList = return. take 1,000,000,000 $ repeat 15
The program ended with a memory error.
Question: how can I improve the program so that it can process lists of any size?
Edit:
, , runghc. ghc 3 . 0.6GBytes. .
native executable ghc haskell03.hs -o haskell03 ./haskell03 >out03.txt, 20 /. , 57GBytes. - 47 .