
Hi, Am Dienstag, den 16.06.2015, 03:37 -0400 schrieb Ken Takusagawa II:
In the following program, the function "test1" results in huge memory usage, but substituting "test2", which does essentially the same thing, does not. GHC 7.10.1, AMD64. Is there a different implementation of replicateM that avoids the space leak?
module Main where { import Control.Monad;
numbers :: [Int]; numbers=[1..200];
-- has a space leak test1 :: [[Int]]; test1 = replicateM 4 numbers;
-- no space leak test2 :: [[Int]]; test2 = do { x1 <- numbers; x2 <- numbers; x3 <- numbers; x4 <- numbers; return [x1,x2,x3,x4]; };
main :: IO(); main = print $ length $ test1;
}
Could be the state hack causing `numbers` to inline, see http://stackoverflow.com/questions/29404065/why-does-this-haskell-code-run-s... and https://ghc.haskell.org/trac/ghc/ticket/9349 Greetings, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • http://www.joachim-breitner.de/ Jabber: nomeata@joachim-breitner.de • GPG-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org